Describe the bug
The built-in tuple type cannot be parametrised using the ellipsis or empty tuple and does not accept more than one argument, i.e. it behaves like a sequence.
To Reproduce
Type check the snippet below.
Expected behavior
That it should behave like typing.Tuple.
Screenshots or Code
from __future__ import annotations
# Variable length homogenous tuple:
# Too many type arguments provided; expected 1 but received 2
# "..." not allowed in this context
foo: tuple[str, ...] = ('a', 'b')
# Empty tuple:
# Expected class type but received "Tuple[()]"
bar: tuple[()] = ()
# Fixed length or heterogenous tuple:
# Too many type arguments provided; expected 1 but received 2
fuz: tuple[str, str] = ('a', 'b')
VS Code extension or command-line
Extension, 1.1.69
Thanks for filing this issue. This will be addressed in the next release of pyright.
This is now addressed in Pyright 1.1.70, which I just published. It will also be in the next version of Pylance.
Thanks for getting this in. I took the new version for a spin and I think tuples are not handled correctly when they're aliased:
Foo = Union['tuple[str, int]']
# Expression of type "Tuple[Literal[''], Literal[0]]" cannot be assigned to declared type "Foo"
# 聽聽TypeVar "_T_co" is covariant
# 聽聽聽聽Type "Literal['', 0]" cannot be assigned to type "str"
# 聽聽聽聽聽聽"Literal[0]" is incompatible with "str"
foo: Foo = ('', 0)
Bar = Tuple[str, int]
bar: Bar = ('', 0) # All good
Thanks. As you discovered, I missed one code path in my previous attempt to fix this. It will be fixed in the next release.
This is now addressed in Pyright 1.1.71, which I just published.
Most helpful comment
Thanks. As you discovered, I missed one code path in my previous attempt to fix this. It will be fixed in the next release.