Pyright: PEP 585 tuple cannot be parametrised like typing.Tuple

Created on 8 Sep 2020  路  5Comments  路  Source: microsoft/pyright

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

addressed in next version bug

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.

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings