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

bpo-43224: Fix Tuple[()].__args__ #31845

Closed
wants to merge 1 commit into from
Closed

Conversation

mrahtz
Copy link
Contributor

@mrahtz mrahtz commented Mar 13, 2022

Here's a fun inconsistency:

>>> Tuple[()].__args__
((),)
>>> tuple[()].__args__
()

Even though there's an explicit test for the former behaviour, I don't think it's right:

  • Argument 1: If foo.__args__ is (bar,), that says that foo is being parameterised by bar. When we do Tuple[()], it's really just to get around the fact that Tuple[] is invalid syntax - what we're really meaning to say is that we're not parameterising it with anything. Tuple[()].__args__ should therefore be empty.
  • Argument 2: Everything in Tuple[...].__args__ should be a type. () is not a type.

This matters for PEP 646, where we were expecting that a TypeVarTuple with no arguments would expand to nothing rather than (). If we were to change things so it was consistent with the current behaviour of Tuple[()], we'd have

T = TypeVar('T')
Ts = TypeVarTuple('Ts')
class C(Generic[T, *Ts]): pass
Alias = C[int, *Ts]
Alias[()]  # C[int, ()]

which definitely isn't what we want.

@ilevkivskyi who added the test for the former behaviour, according to the git blame. Is there something I'm missing here?

https://bugs.python.org/issue43224

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 13, 2022

Looks like this conflicts with (and accomplishes the same thing as?) #31836

@mrahtz
Copy link
Contributor Author

mrahtz commented Mar 13, 2022

Oops, good catch! Closing.

@mrahtz mrahtz closed this Mar 13, 2022
@mrahtz mrahtz deleted the fix-tuple-args branch April 5, 2022 18:41
@mrahtz mrahtz mannequin mentioned this pull request Apr 11, 2022
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