Returning a different class in #[new]
method
#2801
-
In Python you can do: class A:
pass
class B:
def __new__(self, name):
return A() and I would like to do the same with #[pyclass]
pub struct A {}
#[pyclass]
pub struct B {}
#[pymethods]
impl B {
#[new]
pub fn __new__() -> A {
A {}
}
} as I get:
Does anyone know how to implement this? |
Beta Was this translation helpful? Give feedback.
Answered by
davidhewitt
Dec 8, 2022
Replies: 1 comment
-
This fits with #2384 - currently |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
benruijl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This fits with #2384 - currently
#[new]
assumes you want to build a new object ofSelf
type each time, but really we should relax this restriction (just needs someone to work out the implementation).