Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
bpo-29262: Add get_origin() and get_args() introspection helpers to typing#13685
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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.
Fix the typo and land it!
Uh oh!
There was an error while loading.Please reload this page.
Could you go into the rationale for normalization a bit more? I would prefer that |
…yping (pythonGH-13685)This is an old feature request that appears from time to time. After a year of experimenting with various introspection capabilities in `typing_inspect` on PyPI, I propose to add these two most commonly used functions: `get_origin()` and `get_args()`. These are essentially thin public wrappers around private APIs: `__origin__` and `__args__`.As discussed in the issue and on the typing tracker, exposing some public helpers instead of `__origin__` and `__args__` directly will give us more flexibility if we will decide to update the internal representation, while still maintaining backwards compatibility.The implementation is very simple an is essentially a copy from `typing_inspect` with one exception: `ClassVar` was special-cased in `typing_inspect`, but I think this special-casing doesn't really help and only makes things more complicated.
The implementations come from CPython commit 427c84f13f77 with one smallchange – the get_origin's docstring mentions Annotated as it's alsosupported.get_origin() and get_args() introduced in [1] and modified in [2] tosupport Annotated.[1]python/cpython#13685[2]python/cpython#18260
The implementations come from CPython commit 427c84f13f77 with one smallchange – the get_origin's docstring mentions Annotated as it's alsosupported.get_origin() and get_args() introduced in [1] and modified in [2] tosupport Annotated.[1]python/cpython#13685[2]python/cpython#18260* Define our own get_origin()/get_args() in typing_extensions on Python 3.8Otherwise typing_extensions.get_origin() would not recognizetyping_extensions.Annotated on 3.8.
The implementations come from CPython commit 427c84f13f77 with one smallchange – the get_origin's docstring mentions Annotated as it's alsosupported.get_origin() and get_args() introduced in [1] and modified in [2] tosupport Annotated.[1]python/cpython#13685[2]python/cpython#18260* Define our own get_origin()/get_args() in typing_extensions on Python 3.8Otherwise typing_extensions.get_origin() would not recognizetyping_extensions.Annotated on 3.8.
The implementations come from CPython commit 427c84f13f77 with one smallchange – the get_origin's docstring mentions Annotated as it's alsosupported.get_origin() and get_args() introduced in [1] and modified in [2] tosupport Annotated.[1]python/cpython#13685[2]python/cpython#18260* Define our own get_origin()/get_args() in typing_extensions on Python 3.8Otherwise typing_extensions.get_origin() would not recognizetyping_extensions.Annotated on 3.8.
Uh oh!
There was an error while loading.Please reload this page.
This is an old feature request that appears from time to time. After a year of experimenting with various introspection capabilities in
typing_inspecton PyPI, I propose to add these two most commonly used functions:get_origin()andget_args(). These are essentially thin public wrappers around private APIs:__origin__and__args__.As discussed in the issue and on the typing tracker, exposing some public helpers instead of
__origin__and__args__directly will give us more flexibility if we will decide to update the internal representation, while still maintaining backwards compatibility.The implementation is very simple an is essentially a copy from
typing_inspectwith one exception:ClassVarwas special-cased intyping_inspect, but I think this special-casing doesn't really help and only makes things more complicated.https://bugs.python.org/issue29262