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
When using #[pyclass] on a "complex" enum, PyO3 generates a sub-class for each variant, so that you can use isinstance. Is it possible to implement something similar manually, if I'm wrapping an external enum?
I can define #[classmethod]s for each variant, but sub-classes might be nicer, if they are not too terribly difficult to implement.
E.g.:
// External cratepubenumSomething{This(This),That(That),}// My bindings#[pyclass]pubstructPySomething(Something);#[pymethods]implPySomething{// I can do this, but then I won't be able to use `isinstance` to differentiate variants 🤔#[classmethod]fnthis() -> Self{Self(Something::This(This::default()))}}// How do I annotate/implement `PySomethingThis` so that it's similar to auto-generated `This` sub-class// when `#[pyclass]` is used on `Something` directly? #[pyclass]pubstructPySomethingThis;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using
#[pyclass]on a "complex" enum, PyO3 generates a sub-class for each variant, so that you can useisinstance. Is it possible to implement something similar manually, if I'm wrapping an external enum?I can define
#[classmethod]s for each variant, but sub-classes might be nicer, if they are not too terribly difficult to implement.E.g.:
Beta Was this translation helpful? Give feedback.
All reactions