Support for arbitraty generics#416
Conversation
Unwrap _GenericAlias to its origin class before calling get_type_hints, get_constructor_signature, and WithEnforcement, all of which require a plain class rather than a parameterized alias. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
|
…tor sig
When proxy_for_class receives Container[int], use get_bindings_from_type_arguments
to build {T: int} and realize() each constructor parameter annotation before
gen_args sees it, so the generated proxy has the correct concrete types.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Classes like torch DataLoader have forward references that can't be resolved outside their defining module, causing NameError. Fall back to empty dict so proxy_for_class can still attempt construction via the constructor signature. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
pschanely
left a comment
There was a problem hiding this comment.
Not slop, as far as I can tell. Thank you for the contribution!
I have a few (hopefully small) requests; feel free to add yourself at the bottom of contributing.rst too.
- Narrow get_type_hints exception handling to (AttributeError, NameError) - Move TypeVar KeyError fallback into dynamic_typing.realize via .get() - Add tests for parameterized generic proxies, multi-TypeVar, and unresolvable forward ref fallback - Add contributor entry for Antonin Peronnet Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Consistent with existing test file style. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Is that ok now ? |
Just a few more mypy typing issues, but otherwise this looks great! |
|
I'm confused about the |
The last commit added # type: ignore[union-attr] but the actual mypy error is attr-defined, not union-attr. Co-authored-by: DeepSeek <noreply@ai.dev>
Unfortunately there are a lot of warning messages in there (I'll file an issue about this presently); for now, you only need to look at the errors. |
|
Only hypothesis failing |
- Narrow get_type_hints exception handling to (AttributeError, NameError) - Move TypeVar KeyError fallback into dynamic_typing.realize via .get() - Add tests for parameterized generic proxies, multi-TypeVar, and unresolvable forward ref fallback - Add contributor entry for Antonin Peronnet Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This is my attempt to fix #415
To be clear:
If you consider it's slop and close it, I will have no problem with that.
Have a nice day !