-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
bpo-29262: Add get_origin() and get_args() introspection helpers to typing #13685
Merged
ilevkivskyi
merged 4 commits into
python:master
from
ilevkivskyi:add-typing-introspection
May 30, 2019
Merged
bpo-29262: Add get_origin() and get_args() introspection helpers to typing #13685
ilevkivskyi
merged 4 commits into
python:master
from
ilevkivskyi:add-typing-introspection
May 30, 2019
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gvanrossum
approved these changes
May 30, 2019
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!
Could you go into the rationale for normalization a bit more? I would prefer that |
DinoV
pushed a commit
to DinoV/cpython
that referenced
this pull request
Jan 14, 2020
…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.
jstasiak
added a commit
to jstasiak/typing
that referenced
this pull request
Feb 6, 2020
The implementations come from CPython commit 427c84f13f77 with one small change – the get_origin's docstring mentions Annotated as it's also supported. get_origin() and get_args() introduced in [1] and modified in [2] to support Annotated. [1] python/cpython#13685 [2] python/cpython#18260
gvanrossum
pushed a commit
to python/typing
that referenced
this pull request
Feb 7, 2020
The implementations come from CPython commit 427c84f13f77 with one small change – the get_origin's docstring mentions Annotated as it's also supported. get_origin() and get_args() introduced in [1] and modified in [2] to support Annotated. [1] python/cpython#13685 [2] python/cpython#18260 * Define our own get_origin()/get_args() in typing_extensions on Python 3.8 Otherwise typing_extensions.get_origin() would not recognize typing_extensions.Annotated on 3.8.
JelleZijlstra
pushed a commit
to python/typing_extensions
that referenced
this pull request
May 19, 2022
The implementations come from CPython commit 427c84f13f77 with one small change – the get_origin's docstring mentions Annotated as it's also supported. get_origin() and get_args() introduced in [1] and modified in [2] to support Annotated. [1] python/cpython#13685 [2] python/cpython#18260 * Define our own get_origin()/get_args() in typing_extensions on Python 3.8 Otherwise typing_extensions.get_origin() would not recognize typing_extensions.Annotated on 3.8.
JelleZijlstra
pushed a commit
to python/typing_extensions
that referenced
this pull request
May 19, 2022
The implementations come from CPython commit 427c84f13f77 with one small change – the get_origin's docstring mentions Annotated as it's also supported. get_origin() and get_args() introduced in [1] and modified in [2] to support Annotated. [1] python/cpython#13685 [2] python/cpython#18260 * Define our own get_origin()/get_args() in typing_extensions on Python 3.8 Otherwise typing_extensions.get_origin() would not recognize typing_extensions.Annotated on 3.8.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()
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_inspect
with one exception:ClassVar
was 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