-
Notifications
You must be signed in to change notification settings - Fork 905
Basic introspection of #[derive(FromPyObject)] #5339
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
Conversation
| const DOC: &'static CStr; | ||
|
|
||
| #[cfg(feature = "experimental-inspect")] | ||
| const TYPE_NAME: &'static str; |
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.
Useful to initialize FromPyObject::INPUT_TYPE in the blanket impl impl<T> FromPyObject<'_> for T
| } | ||
| ContainerType::Struct(_) => { | ||
| // TODO: implement using a Protocol? | ||
| builder.push_str("_typeshed.Incomplete") |
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.
_typeshed.Incomplete is an alias of typing.Any that hints that the type should be edited to something smaller: https://typing.python.org/en/latest/guides/writing_stubs.html#incomplete-stubs
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.
A protocol seems like the right approach; we want to describe the shape of what we expect without any knowledge of its actual type, given we fully duck-type the extraction.
Struct fields are not supported yet
1ed5d3f to
a3e0bc4
Compare
davidhewitt
left a comment
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.
LGTM, very nice to see all these pieces coming together, thanks!
| } | ||
| ContainerType::Struct(_) => { | ||
| // TODO: implement using a Protocol? | ||
| builder.push_str("_typeshed.Incomplete") |
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.
A protocol seems like the right approach; we want to describe the shape of what we expect without any knowledge of its actual type, given we fully duck-type the extraction.
| // We don't know what from_py_with is doing | ||
| builder.push_str("_typeshed.Incomplete") |
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.
It would be interesting to discuss how we make this work, I guess some manually-applied type hint would be the only way.
Struct fields are not supported yet. Doing it cleanly might require a mix of
typing.Protocolandtyping.TypedDict