Skip to content

Commit 053118d

Browse files
added tuple-typeshed fixture
1 parent be85cef commit 053118d

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

test-data/unit/check-expressions.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ s = A() + B() # E: Unsupported operand types for + ("A" and "B")
686686
from typing import assert_type, Never
687687

688688
class Size(tuple[int, ...]):
689-
def __add__(self, other: tuple[int, ...], /) -> "Size": return Size()
689+
def __add__(self, other: tuple[int, ...], /) -> "Size": return Size() # type: ignore[override]
690690
def __radd__(self, other: tuple[int, ...], /) -> "Size": return Size()
691691

692692
size: Size = Size([3, 4])
@@ -702,7 +702,7 @@ assert_type(tup2 + size, Size)
702702
assert_type(tupN + size, Size)
703703
assert_type(tupX + size, Size)
704704

705-
[builtins fixtures/tuple.pyi]
705+
[builtins fixtures/tuple-typeshed.pyi]
706706

707707
[case testBinaryOperatorWithAnyRightOperand]
708708
from typing import Any, cast
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# tuple definition from typeshed,
2+
from typing import (
3+
Generic,
4+
Sequence,
5+
TypeVar,
6+
Iterable,
7+
Iterator,
8+
Any,
9+
overload,
10+
Self,
11+
Protocol,
12+
)
13+
from types import GenericAlias
14+
15+
_T = TypeVar("_T")
16+
_T_co = TypeVar('_T_co', covariant=True)
17+
18+
class tuple(Sequence[_T_co], Generic[_T_co]):
19+
def __new__(cls, iterable: Iterable[_T_co] = ..., /) -> Self: ...
20+
def __len__(self) -> int: ...
21+
def __contains__(self, key: object, /) -> bool: ...
22+
@overload
23+
def __getitem__(self, key: SupportsIndex, /) -> _T_co: ...
24+
@overload
25+
def __getitem__(self, key: slice, /) -> tuple[_T_co, ...]: ...
26+
def __iter__(self) -> Iterator[_T_co]: ...
27+
def __lt__(self, value: tuple[_T_co, ...], /) -> bool: ...
28+
def __le__(self, value: tuple[_T_co, ...], /) -> bool: ...
29+
def __gt__(self, value: tuple[_T_co, ...], /) -> bool: ...
30+
def __ge__(self, value: tuple[_T_co, ...], /) -> bool: ...
31+
def __eq__(self, value: object, /) -> bool: ...
32+
def __hash__(self) -> int: ...
33+
@overload
34+
def __add__(self, value: tuple[_T_co, ...], /) -> tuple[_T_co, ...]: ...
35+
@overload
36+
def __add__(self, value: tuple[_T, ...], /) -> tuple[_T_co | _T, ...]: ...
37+
def __mul__(self, value: SupportsIndex, /) -> tuple[_T_co, ...]: ...
38+
def __rmul__(self, value: SupportsIndex, /) -> tuple[_T_co, ...]: ...
39+
def count(self, value: Any, /) -> int: ...
40+
def index(self, value: Any, start: SupportsIndex = ..., stop: SupportsIndex = ..., /) -> int: ...
41+
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
42+
43+
class dict: pass
44+
class int: pass
45+
class slice: pass
46+
class bool(int): pass
47+
class str: pass # For convenience
48+
class object: pass
49+
class type: pass
50+
class ellipsis: pass
51+
class SupportsIndex(Protocol):
52+
def __index__(self) -> int: pass
53+
class list(Sequence[_T], Generic[_T]):
54+
@overload
55+
def __getitem__(self, i: int) -> _T: ...
56+
@overload
57+
def __getitem__(self, s: slice) -> list[_T]: ...
58+
def __contains__(self, item: object) -> bool: ...
59+
def __iter__(self) -> Iterator[_T]: ...

0 commit comments

Comments
 (0)