bpo-43224: Fix Tuple[()].__args__ by mrahtz · Pull Request #31845 · python/cpython
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 thatfoois being parameterised bybar. When we doTuple[()], it's really just to get around the fact thatTuple[]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?