You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'd like to make a pyclass with a classattr and regular attribute with the same name. See this example:
#[pyclass]structPyO3Class{#[pyo3(get, set)]attr:i32,}#[pymethods]implPyO3Class{#[new]fnnew(attr:i32) -> Self{Self{ attr }}#[classattr]fnattr() -> String{"From the class".to_string()}}
My expectation based on standard Python behaviour is that when I access .attr on a class, I should get the string from the classattr, whereas on an instance I get the integer value out from the instance.
For context, I want different behaviours when accessing the attribute on the class and from an instance as I'm trying to implement a PySpark-inspired interface, see this Python pseudo-code:
Hi, I'd like to make a pyclass with a classattr and regular attribute with the same name. See this example:
My expectation based on standard Python behaviour is that when I access
.attr
on a class, I should get the string from the classattr, whereas on an instance I get the integer value out from the instance.See this Python code demonstrating this:
outputting:
However, from PyO3 class above, the equivalent code:
outputs:
I've tried a few other patterns to try and get this to work:
#[getter]
explicitly and play with the orderPyO3Class::type_object(py).setattr("attr", "From the class")
on module initialisationHowever all resulted in the same behaviour.
I've opened this issue as suggested by @davidhewitt on Discord.
The text was updated successfully, but these errors were encountered: