How can I returns an instance of child class in instance methods #2344
-
for example: #[pymethods]
impl CredentialProvider {
#[args(opts = "GetOptions::default()")]
#[pyo3(text_signature = "($self, opts)")]
fn get(&self, opts: GetOptions) -> PyResult<(Credential, CredentialProvider)> {
Ok((
Credential,
CredentialProvider(Box::new(self.0.get(opts.0)?.into_credential())),
))
}
} Credential is child class and CredentialProvider is its parent class. The rust compiler says:
how to resolve it? Thanks. |
Beta Was this translation helpful? Give feedback.
Answered by
davidhewitt
May 4, 2022
Replies: 2 comments
-
Sorry for the slow reply. I think you can achieve this by using #[pymethods]
impl CredentialProvider {
#[args(opts = "GetOptions::default()")]
#[pyo3(text_signature = "($self, opts)")]
fn get(&self, opts: GetOptions) -> PyResult<Py<CredentialProvider>> {
Py::new((
Credential,
CredentialProvider(Box::new(self.0.get(opts.0)?.into_credential())),
))
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
bachue
-
@davidhewitt OK, Thanks for your reply. |
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
Sorry for the slow reply. I think you can achieve this by using
Py::new
, although it's not well documented. I'd love to make this bit of PyO3's API better.