How to return a Python list of Union type pyclass objects? #2373
-
Hi there, #[pyclass]
pub struct Foo {
...
}
#[pyclass]
pub struct Bar {
...
}
// Foo and Bar are all pyclasses
enum GenericType {
FooType(Foo),
BarType(Bar),
}
#[pyclass]
pub struct GenericWrapper{
inner: GenericType,
}
#[pyfunction]
pub fn read_from_file(path: &str) -> Vec<GenericWrapper> {
...
} _arr = read_from_file(path="somewhere")
arr = [x.extract_as_foo_or_bar() for x in _arr] It reads contents from a file and return a list of pyclass objects. I tried to use |
Beta Was this translation helpful? Give feedback.
Answered by
birkenfeld
May 14, 2022
Replies: 1 comment 2 replies
-
First question - do you need the |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
tushushu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First question - do you need the
GenericWrapper
at all? You could just returnVec<PyObject>
fromread_from_file
...