Basic introspection of #[derive(FromPyObject)] - #5339
Conversation
| const DOC: &'static CStr; | ||
|
|
||
| #[cfg(feature = "experimental-inspect")] | ||
| const TYPE_NAME: &'static str; |
There was a problem hiding this comment.
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.
_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.
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.
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.
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.
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