Is it possible to initialise a subclass of a class defined in rust? #2729
Unanswered
samuelcolvin
asked this question in
Questions
Replies: 2 comments 7 replies
-
Ping. Anyone able to give and feedback on this? Would be great to know even if the answer is "no, you're crazy, that's impossible". |
Beta Was this translation helpful? Give feedback.
6 replies
-
With the additional info I could glean from your recent comment in #2347, let me have one more go: It is not possible to create an instance of When you have an instance of |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I assume this is impossible, but since it would be a massive win for pydantic, I thought it worth asking.
Let's say I have:
Because
MyClass
is marked with#[pyclass(subclass)]
I can subclass it in python.Is it possible to pass
MySubclass
back to pyo3/rust code and create instances ofMySubclass
using thewith_capacity
method or similar.E.g. is it somehow possible to tell rust that I have a variant of
MyClass
with some kind of pointer pointing to it's subclass but that it's aMyClass
and therefore has awith_capacity
method?So something like
Or equivilantly, is it possible to create a
MyClass
instance, then cast it to aMySubclass
?Beta Was this translation helpful? Give feedback.
All reactions