Skip to content

Backport get_origin() and get_args() #698

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

Merged
merged 4 commits into from
Feb 7, 2020

Conversation

jstasiak
Copy link
Contributor

@jstasiak jstasiak commented 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

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
Contributor Author

jstasiak commented Feb 6, 2020

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
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
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)

Copy link
Member

@gvanrossum gvanrossum left a comment

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.

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

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:master Feb 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants