-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow other Result types in #[pyfunction]
etc
#1106
Comments
Broadly speaking, I don't think the implementation is too hard. I think we can just replace these lines in Lines 40 to 47 in 4840619
with this implementation:
However, at the moment this causes So our internal code would need a little refactoring, but otherwise it's reasonably straightforward. |
Note that the question mark operator already calls into() so I don't think the flexibility implementing the pyfunction is really needed. The other pros might be nice though. |
I'm the one who suggested this feature, and yes, you got it right. I think that as long as it's well documented, it shouldn't be an issue. This should be mentioned in the type conversions table of the book with a note that the wrapped Error must implement I could implement this myself but I'm very new to pyo3 so I would need a bit of hand holding. Not sure if I should. |
@marioortizmanero if you're interested in implementing this then you're very welcome to provide a PR! I'm happy to review or answer any questions you have. |
Thanks @davidhewitt, I've opened a new PR at #1118 with the proposed changes. Please take a look and let me know. |
This can be closed now as #1118 was merged, @davidhewitt |
Thanks 👍 |
At the moment the only
Result
type we allow in#[pyfunction]
isPyResult
.After a question on Gitter yesterday I was thinking if we can allow instead any
Result
which hasE: Into<PyErr>
.That would allow code like this (all implementations replaced with
...
):Pros:
#[pyfunction]
#[pyfunction]
in Rust - can handleMyError
typed enum rather than dynamicPyErr
.#[pyfunction]
in Rust - no need to createPyErr
which is relatively higher-cost thanMyError
.Cons:
cc @marioortizmanero who posted on this topic on Gitter. (At least, I think that was what was being asked!)
The text was updated successfully, but these errors were encountered: