Skip to content
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

Support most use cases for PEP 612 with Generic #817

Merged
merged 9 commits into from Jun 16, 2021

Conversation

Fidget-Spinner
Copy link
Member

@Fidget-Spinner Fidget-Spinner commented Jun 11, 2021

Support PEP 612 and most user-defined generics use cases. This also brings the PEP 612 test suite to near parity with CPython. Note some limitations in valid use cases below simply because of runtime limitations.

Fixes #816.

@JelleZijlstra
Copy link
Member

Thanks! Looks good but let's see what CI says. When I tried this locally on 3.6 it failed with AttributeError: 'ParamSpec' object has no attribute '_get_type_vars'., so we may have to add that method.

@Fidget-Spinner
Copy link
Member Author

Fidget-Spinner commented Jun 11, 2021

Thanks! Looks good but let's see what CI says. When I tried this locally on 3.6 it failed with AttributeError: 'ParamSpec' object has no attribute '_get_type_vars'., so we may have to add that method.

Thanks for testing. I managed to get it working locally in 3.6 after much spelunking (wow, typing was so different back then).

I don't think I can get the runtime __args__ tests to pass with 3.5.2. Here's a copy from the CI:

=================================== FAILURES ===================================
________________________ ParamSpecTests.test_valid_uses ________________________
self = <test_typing_extensions.ParamSpecTests testMethod=test_valid_uses>
    def test_valid_uses(self):
        P = ParamSpec('P')
        T = TypeVar('T')
        C1 = typing.Callable[P, int]
>       self.assertEqual(C1.__args__, (P, int))
E       AssertionError: Tuples differ: (~P,) != (~P, <class 'int'>)
E       
E       Second tuple contains 1 additional elements.
E       First extra element 1:
E       <class 'int'>
E       
E       - (~P,)
E       + (~P, <class 'int'>)
typing_extensions/src_py3/test_typing_extensions.py:2015: AssertionError

Callable in 3.5.2 looks a little strange. Is this a bug in 3.5.2 or am I missing something here?
https://github.com/python/cpython/blob/91185fe0284a04162e0b3425b53be49bdbfad67d/Lib/typing.py#L762

Other than that, all other versions pass. I'm tempted to just drop 3.5.2 as it's already EOL anyways.

@gvanrossum
Copy link
Member

gvanrossum commented Jun 11, 2021 via email

@JelleZijlstra JelleZijlstra merged commit a114379 into python:master Jun 16, 2021
@JelleZijlstra
Copy link
Member

Thank you!

@Fidget-Spinner Fidget-Spinner deleted the pep612-generics branch June 16, 2021 14:48
@jaraco
Copy link
Member

jaraco commented Aug 29, 2021

This change appears implicated in #865.

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.

Paramspec support in Generic
5 participants