Skip to content

Commit 0ce9e69

Browse files
author
Guido van Rossum
committed
Fix #2184. Bare Tuple should mean Tuple[Any, ...].
1 parent 2fbf387 commit 0ce9e69

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎mypy/typeanal.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
107107
elif fullname == 'typing.Any':
108108
return AnyType()
109109
elif fullname == 'typing.Tuple':
110+
if len(t.args) == 0: # Bare 'Tuple' is same as 'tuple'
111+
return self.builtin_type('builtins.tuple', [AnyType()])
110112
if len(t.args) == 2 and isinstance(t.args[1], EllipsisType):
111113
# Tuple[T, ...] (uniform, variable-length tuple)
112114
node = self.lookup_fqn_func('builtins.tuple')

‎test-data/unit/check-tuples.test‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,3 +820,20 @@ from typing import List, Tuple
820820
def f() -> Tuple[List[str], ...]:
821821
return ([],)
822822
[builtins fixtures/tuple.pyi]
823+
824+
[case testTupleWithoutArgs]
825+
from typing import Tuple
826+
def f(a: Tuple) -> None: pass
827+
f(())
828+
f((1,))
829+
f(('', ''))
830+
[builtins fixtures/tuple.pyi]
831+
832+
[case testTupleSingleton]
833+
# flags: --fast-parser
834+
from typing import Tuple
835+
def f(a: Tuple[()]) -> None: pass
836+
f(())
837+
f((1,)) # E
838+
f(('', '')) # #
839+
[builtins fixtures/tuple.pyi]

‎test-data/unit/fixtures/tuple.pyi‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ T = TypeVar('T')
2525
class list(Sequence[T], Generic[T]): pass
2626

2727
def sum(iterable: Iterable[T], start: T = None) -> T: pass
28-
29-
True = bool()

0 commit comments

Comments
 (0)