Skip to content

Backport get_origin() and get_args() - #698

Merged
gvanrossum merged 4 commits into
python:masterfrom
jstasiak:backport-get_origin-get_args
Feb 7, 2020
Merged

Backport get_origin() and get_args()#698
gvanrossum merged 4 commits into
python:masterfrom
jstasiak:backport-get_origin-get_args

Conversation

@jstasiak

Copy link
Copy Markdown
Contributor

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

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
… 3.8
Otherwise typing_extensions.get_origin() would not recognize
typing_extensions.Annotated on 3.8.
@jstasiak

Copy link
Copy Markdown
ContributorAuthor

Well, I'm not sure what to do regarding the build failure:

_____________ AllTests.test_typing_extensions_defers_when_possible _____________
self = <test_typing_extensions.AllTests testMethod=test_typing_extensions_defers_when_possible>
def test_typing_extensions_defers_when_possible(self):
exclude = {
'overload',
'Text',
'TypedDict',
'TYPE_CHECKING',
'Final',
'get_type_hints'
}
for item in typing_extensions.__all__:
if item not in exclude and hasattr(typing, item):
> self.assertIs(
getattr(typing_extensions, item),
getattr(typing, item))
E AssertionError: <function get_args at 0x7fcb84063430> is not <function get_args at 0x7fcb8a0b3c10>
typing_extensions/src_py3/test_typing_extensions.py:1838: AssertionError

It happens because even though 3.8 has get_args and get_origin they don't support PEP 593 Annotated (only Python 3.9 get_origin and get_args do), so I redefine them in typing_extensions on 3.8 anyway, it's a bit of a mess. Is it acceptable to add them to the exclude list?

@gvanrossum

Copy link
Copy Markdown
Member

Yeah, it looks like it belongs in the exclude list (maybe only in 3.8.x?)


# Python 3.8 has get_origin() and get_args() but those implementations aren't
# Annotated-aware, so we can't use those, only Python 3.9 versions will do.
if sys.version_info[:3] >= (3, 9, 0):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys.version_info[:2] >= (3, 9)

@gvanrossumgvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'd wait a few days for @ilevkivskyi -- Ivan, if you're okay with my review just say so and I'll merge it.

@ilevkivskyiilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@gvanrossum
gvanrossum merged commit 7e354ef into python:masterFeb 7, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jstasiak@gvanrossum@ilevkivskyi@the-knights-who-say-ni