-
Notifications
You must be signed in to change notification settings - Fork 806
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
Add support for type hinting objects #4917
Conversation
@ngoldbaum can you have a look at this before the other maintainers? |
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've purposely avoided learning much about Python type hints so I'm not sure why you'd want to use this, although I didn't read the test closely to figure that out.
There is guide/src/python-typing-hints.md
in the narrative docs - can you maybe expand the content there to describe how you might use this?
I will address the comments and try to update other PyO3 documentations related to type hints. But the core motivation is making implementing |
After reading
That way, we can just document that |
it makes clippy fail This reverts commit 3eaf0a1.
Fair enough about the docs! Let’s let another maintainer who knows a bit more about type hint plumbing in Python take a look at this but the FFI bits look correct to me. |
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.
Thanks! FFI bindings look good, I have some suggestions for the safe wrapper 👍
src/types/genericalias.rs
Outdated
py: Python<'py>, | ||
origin: &Bound<'py, PyAny>, | ||
args: &Bound<'py, PyAny>, | ||
) -> Bound<'py, PyGenericAlias> { |
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 API documents that it may fail, so I think we should use PyResult
return value here.
I think it should handle errors now. Also, I will sitck with |
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.
Thanks, just one final suggestion then.
Related to #4849
This PR adds the
pyo3-ffi
bindings to type hinting objectsand then exposes them in
pyo3
.I gated this for Python 3.9+ but I am not confident this is the appropriate way to doing so in PyO3. Is this the idiomatic way? I prefered to gate the whole module instead of individual methods.