Replies: 1 comment
-
|
It was easy enough to add a simple implementation to my enum's pymethods that does the same thing the macro does for structs: #[pyclass]
pub enum MyEnum {
Var1 { x: u8 },
Var2 {},
}
#[pymethods]
impl MyEnum {
// python generics support
#[classmethod]
#[pyo3(signature = (key, /))]
fn __class_getitem__<'py>(
cls: &Bound<'py, PyType>,
key: &Bound<'py, PyAny>,
) -> PyResult<Bound<'py, PyAny>> {
Ok(PyGenericAlias::new(cls.py(), cls.as_any(), key)?.into_any())
}
}The method exists on all the variants because the variants inherit from the outer class, so this is sufficient. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Support for runtime generic typing for structs was added last May in #4926. Is it planned to be added for (complex) enums as well? What are the complications that make this more of a challenge than structs?
Beta Was this translation helpful? Give feedback.
All reactions