Bug Description
In one of my pyo3 projects, I need to have both an 'x' attribute and a 'get_x' method with additional parameters for some more specialized calculations of the value. This naming is necessary for backwards compatibility.
However, this produces an internal compiler error due to naming conflict.
Below you can see that even using 'name = ...' doesn't fix the issue.
Steps to Reproduce
pyo3_naming_limitation working example
Working example, just cargo build. Here is the code contained immediately, for convenience:
#[pyclass]
pub struct Object {
x: u32,
y: u32,
}
#[pymethods]
impl Object {
#[getter]
fn x(&self) -> u32 {
self.x
}
fn get_x(&self) -> u32 {
self.x
}
#[getter]
fn y(&self) -> u32 {
self.y
}
#[pyo3(name = "get_y")]
fn y_get(&self) -> u32 {
self.y
}
}
Backtrace
error[E0592]: duplicate definitions with name `__pymethod_get_x__`
--> src/lib.rs:21:1
|
21 | #[pymethods]
| ^^^^^^^^^^^^
| |
| duplicate definitions for `__pymethod_get_x__`
| other definition for `__pymethod_get_x__`
|
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0592]: duplicate definitions with name `__pymethod_get_y__`
--> src/lib.rs:21:1
|
21 | #[pymethods]
| ^^^^^^^^^^^^
| |
| duplicate definitions for `__pymethod_get_y__`
| other definition for `__pymethod_get_y__`
|
= note: this error originates in the attribute macro `pymethods` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0592`.
error: could not compile `pyo3_limitation` (lib) due to 2 previous errors
Your operating system and version
Debian GNU/Linux 13 (trixie)
Your Python version (python --version)
3.13.9
Your Rust version (rustc --version)
1.94.1
Your PyO3 version
0.27.0
How did you install python? Did you use a virtualenv?
This can be replicated without running python.
Additional Info
No response
Bug Description
In one of my pyo3 projects, I need to have both an 'x' attribute and a 'get_x' method with additional parameters for some more specialized calculations of the value. This naming is necessary for backwards compatibility.
However, this produces an internal compiler error due to naming conflict.
Below you can see that even using 'name = ...' doesn't fix the issue.
Steps to Reproduce
pyo3_naming_limitation working example
Working example, just cargo build. Here is the code contained immediately, for convenience:
Backtrace
Your operating system and version
Debian GNU/Linux 13 (trixie)
Your Python version (
python --version)3.13.9
Your Rust version (
rustc --version)1.94.1
Your PyO3 version
0.27.0
How did you install python? Did you use a virtualenv?
This can be replicated without running python.
Additional Info
No response