-
-
Notifications
You must be signed in to change notification settings - Fork 640
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
PyO3: migrate to using IntoPyObject
#21681
Conversation
.into_pyobject(py)? | ||
.to_owned() | ||
.into_any() | ||
.unbind(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a lot of hoop-jumping to "convert" a Rust bool into a Python bool. Shouldn't this function (even before this change) return PyResult<bool>
and then the formal conversion is a lot simpler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default branch of the match for py.NotImplemented
is what is causing the rest of mess since all three branches have to return the same type. If the function returns PyResult<bool>
then it cannot return NotImplemented
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a solution in mind for a custom enum (with True
, False
, and NotImplemented
variants) which would be convertible from Option<bool>
and convert to the correct Python-side types. But that would be a follow-on PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I would have expected we could raise NotImplementedError
via the PyErr in the PyResult, but I guess technically you are supposed to return the NotImplemented
singleton in comparison operators, and not raise. So this is correct.
As part of upgrading to PyO3 v2.23.x, migrate to using the new
IntoPyObject
conversion trait instead of the now deprecatedIntoPy
andToPyObject
traits. Deprecation warnings are no longer disabled for the affected files.