Skip to content

Commit 9104d55

Browse files
pkchilevkivskyi
authored andcommitted
Make tuple generic in most stubs (#3767)
Make tuples generic in stubs to reduce incompatibility between stubs and production. This is a carve-out from #3129.
1 parent e4d1dc4 commit 9104d55

18 files changed

+41
-26
lines changed

test-data/unit/check-isinstance.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ if isinstance(x): # E: Too few arguments for "isinstance"
17491749

17501750
[case testIsInstanceTooManyArgs]
17511751
isinstance(1, 1, 1) # E: Too many arguments for "isinstance" \
1752-
# E: Argument 2 to "isinstance" has incompatible type "int"; expected "Union[type, tuple]"
1752+
# E: Argument 2 to "isinstance" has incompatible type "int"; expected "Union[type, Tuple[Any, ...]]"
17531753
x: object
17541754
if isinstance(x, str, 1): # E: Too many arguments for "isinstance"
17551755
reveal_type(x) # E: Revealed type is 'builtins.object'

test-data/unit/fixtures/async_await.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import typing
22

33
T = typing.TypeVar('T')
4-
class list(typing.Generic[T], typing.Sequence[T]): pass
4+
U = typing.TypeVar('U')
5+
class list(typing.Sequence[T]): pass
56

67
class object:
78
def __init__(self): pass
89
class type: pass
910
class function: pass
1011
class int: pass
1112
class str: pass
12-
class dict: pass
13-
class set: pass
14-
class tuple: pass
13+
class dict(typing.Generic[T, U]): pass
14+
class set(typing.Generic[T]): pass
15+
class tuple(typing.Generic[T]): pass
1516
class BaseException: pass
1617
class StopIteration(BaseException): pass
1718
class StopAsyncIteration(BaseException): pass

test-data/unit/fixtures/bool.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# builtins stub used in boolean-related test cases.
2+
from typing import Generic, TypeVar
3+
T = TypeVar('T')
24

35
class object:
46
def __init__(self) -> None: pass
57

68
class type: pass
7-
class tuple: pass
9+
class tuple(Generic[T]): pass
810
class function: pass
911
class bool: pass
1012
class int: pass

test-data/unit/fixtures/dict.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class list(Iterable[T], Generic[T]): # needed by some test cases
3535
def __iter__(self) -> Iterator[T]: pass
3636
def __mul__(self, x: int) -> list[T]: pass
3737

38-
class tuple: pass
38+
class tuple(Generic[T]): pass
3939
class function: pass
4040
class float: pass
4141
class bool: pass

test-data/unit/fixtures/exception.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
from typing import Generic, TypeVar
2+
T = TypeVar('T')
13

24
class object:
35
def __init__(self): pass
46

57
class type: pass
6-
class tuple: pass
8+
class tuple(Generic[T]): pass
79
class function: pass
810
class int: pass
911
class str: pass

test-data/unit/fixtures/fine_grained.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# enough to handle them.
55

66
import types
7+
from typing import TypeVar, Generic
8+
9+
T = TypeVar('T')
710

811
class Any: pass
912

@@ -20,7 +23,7 @@ class str:
2023

2124
class float: pass
2225
class bytes: pass
23-
class tuple: pass
26+
class tuple(Generic[T]): pass
2427
class function: pass
2528
class ellipsis: pass
26-
class list: pass
29+
class list(Generic[T]): pass

test-data/unit/fixtures/float.pyi

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from typing import Generic, TypeVar
2+
T = TypeVar('T')
3+
14
Any = 0
25

36
class object:
@@ -12,7 +15,7 @@ class str:
1215

1316
class bytes: pass
1417

15-
class tuple: pass
18+
class tuple(Generic[T]): pass
1619
class function: pass
1720

1821
class ellipsis: pass

test-data/unit/fixtures/floatdict.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class str:
1818

1919
class bytes: pass
2020

21-
class tuple: pass
21+
class tuple(Generic[T]): pass
2222
class function: pass
2323

2424
class ellipsis: pass

test-data/unit/fixtures/for.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class object:
99
def __init__(self) -> None: pass
1010

1111
class type: pass
12-
class tuple: pass
12+
class tuple(Generic[t]): pass
1313
class function: pass
1414
class bool: pass
1515
class int: pass # for convenience

test-data/unit/fixtures/isinstancelist.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from typing import Iterable, Iterator, TypeVar, List, Mapping, overload, Tuple, Set, Union
1+
from typing import Iterable, Iterator, TypeVar, List, Mapping, overload, Tuple, Set, Union, Generic
22

33
class object:
44
def __init__(self) -> None: pass
55

66
class type:
77
def __init__(self, x) -> None: pass
88

9-
class tuple: pass
109
class function: pass
1110
class ellipsis: pass
1211

@@ -24,6 +23,8 @@ T = TypeVar('T')
2423
KT = TypeVar('KT')
2524
VT = TypeVar('VT')
2625

26+
class tuple(Generic[T]): pass
27+
2728
class list(Iterable[T]):
2829
def __iter__(self) -> Iterator[T]: pass
2930
def __mul__(self, x: int) -> list[T]: pass

test-data/unit/fixtures/module.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class function: pass
1313
class int: pass
1414
class str: pass
1515
class bool: pass
16-
class tuple: pass
16+
class tuple(Generic[T]): pass
1717
class dict(Generic[T, S]): pass
1818
class ellipsis: pass
1919

test-data/unit/fixtures/module_all.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ class list(Generic[_T], Sequence[_T]):
1414
def append(self, x: _T): pass
1515
def extend(self, x: Sequence[_T]): pass
1616
def __add__(self, rhs: Sequence[_T]) -> list[_T]: pass
17-
class tuple: pass
17+
class tuple(Generic[_T]): pass
1818
class ellipsis: pass

test-data/unit/fixtures/module_all_python2.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ class list(Generic[_T], Sequence[_T]):
1212
def append(self, x: _T): pass
1313
def extend(self, x: Sequence[_T]): pass
1414
def __add__(self, rhs: Sequence[_T]) -> list[_T]: pass
15-
class tuple: pass
15+
class tuple(Generic[_T]): pass

test-data/unit/fixtures/primitives.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# builtins stub with non-generic primitive types
2+
from typing import Generic, TypeVar
3+
T = TypeVar('T')
24

35
class object:
46
def __init__(self) -> None: pass
@@ -17,5 +19,5 @@ class str:
1719
def format(self, *args) -> str: pass
1820
class bytes: pass
1921
class bytearray: pass
20-
class tuple: pass
22+
class tuple(Generic[T]): pass
2123
class function: pass

test-data/unit/fixtures/set.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class object:
88
def __init__(self) -> None: pass
99

1010
class type: pass
11-
class tuple: pass
11+
class tuple(Generic[T]): pass
1212
class function: pass
1313

1414
class int: pass

test-data/unit/fixtures/slice.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Builtins stub used in slicing test cases.
2+
from typing import Generic, TypeVar
3+
T = TypeVar('T')
24

35
class object:
46
def __init__(self): pass
57

68
class type: pass
7-
class tuple: pass
9+
class tuple(Generic[T]): pass
810
class function: pass
911

1012
class int: pass

test-data/unit/fixtures/type.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class list(Generic[T]): pass
1313
class type:
1414
def mro(self) -> List['type']: pass
1515

16-
class tuple: pass
16+
class tuple(Generic[T]): pass
1717
class function: pass
1818
class bool: pass
1919
class int: pass

test-data/unit/fixtures/union.pyi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# Builtins stub used in tuple-related test cases.
22

33
from isinstance import isinstance
4-
from typing import Iterable, TypeVar
4+
from typing import Iterable, TypeVar, Generic
5+
T = TypeVar('T')
56

67
class object:
78
def __init__(self): pass
89

910
class type: pass
1011
class function: pass
1112

12-
# Current tuple types get special treatment in the type checker, thus there
13-
# is no need for type arguments here.
14-
class tuple: pass
13+
class tuple(Generic[T]): pass
1514

1615
# We need int for indexing tuples.
1716
class int: pass

0 commit comments

Comments
 (0)