Now that we’re back from the holidays, I’d like to see if we can come to a resolution on this topic.
To summarize, we were considering four options:
2a: tuple[Any, ...] follows the same rules as tuple[T, ...] . It implies a union of tuple[()] | tuple[Any] | tuple[Any, Any] | ... . tuple is a synonym for tuple[Any, ...] .
2b: Unlike the general case of tuple[T, ...] , tuple[Any, ...] is considered a gradual type. It is bidirectionally type compatible with any tuple regardless of length. tuple is a synonym for tuple[Any, ...] .
2c: We introduce a new form tuple[...] , a gradual type that is bidirectionally type compatible with any tuple of any length. The type tuple[Any, ...] is treated as described in option 2a. tuple is a synonym of tuple[...] .
2d: tuple[Any, ...] follows the same rules as tuple[T, ...]. The “bare” form of tuple (with no type arguments) is a gradual type that is bidirectionally type compatible with any tuple of any length.
- 2a is consistent with pyright’s current implementation.
- 2b is consistent with mypy’s current implementation.
- 2c is consistent with the use of
... in Callable. I’ll note that tuple[...] is evaluated without error by older versions of Python. This option provides partial backward compatibility for mypy users (those who are relying on the “bare” tuple to be a gradual type).
- 2c and 2d are very similar except that 2c provides an unambiguous way to spell the bidirectional form.
When I recently wrote the conformance tests for the typing spec, I ran across a use case described in PEP 646 that legitimately requires a tuple[Any, ...] that is bidirectionally compatible with all tuples of any length. That, along with some of the arguments above, shifts my view on option 2a, which doesn’t provide a solution for these use cases.
I remain strongly opposed to 2d for multiple reasons, so I’d prefer to take that off the table.
That leaves 2b and 2c, both of which I think are viable. I have a slight preference for 2c. The inconsistency of 2b bothers me, but I can understand the appeal of retaining full backward compatibility for mypy users. So I could get behind 2b if that’s the majority consensus.