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
I was just exploring the expanded macro source of the library I am working on and was curious if I could increase the performance of, say __len__ by avoiding the reference to &self. For context this is a Vector3(x, y, z) whose __len__ will always return 3.
So long story short, I think there's a bug here... specifically that slot methods that are also staticmethods try to pass an unsafe object pointer into the static method (at least for __len__).
The text was updated successfully, but these errors were encountered:
willstott101
changed the title
Cannot create slot (__len__) methods with static result.
Cannot create slot (__len__) methods with staticmethod annotation
Mar 11, 2023
Looks like this also works even for things like __add__ (although I can't really see why you'd want to do that).
I see no reason why we should prevent this pattern, so I'll have a play and see how easily we can support it. Certainly the current state of the implementation is a bug.
I was just exploring the expanded macro source of the library I am working on and was curious if I could increase the performance of, say
__len__
by avoiding the reference to&self
. For context this is aVector3(x, y, z)
whose__len__
will always return3
.So to start with I have this:
which is fine, but there's a load of code generated around this call.
If I switch to an associated function (still within
#[pymethods]
):pyo3 asks me to mark it as a
#[staticmethod]
:However if I add that annotation:
As you can see the generated code is wrong:
So long story short, I think there's a bug here... specifically that slot methods that are also staticmethods try to pass an unsafe object pointer into the static method (at least for
__len__
).The text was updated successfully, but these errors were encountered: