|
1 | 1 | import sys |
2 | 2 | from _typeshed import SupportsGetItem |
3 | 3 | from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence |
4 | | -from typing import Any, AnyStr, Generic, Protocol, SupportsAbs, SupportsIndex, TypeVar, final, overload |
5 | | -from typing_extensions import ParamSpec, TypeAlias, TypeIs, TypeVarTuple, Unpack |
| 4 | +from operator import attrgetter as attrgetter, itemgetter as itemgetter, methodcaller as methodcaller |
| 5 | +from typing import Any, AnyStr, Protocol, SupportsAbs, SupportsIndex, TypeVar, overload |
| 6 | +from typing_extensions import ParamSpec, TypeAlias, TypeIs |
6 | 7 |
|
7 | 8 | _R = TypeVar("_R") |
8 | 9 | _T = TypeVar("_T") |
9 | 10 | _T_co = TypeVar("_T_co", covariant=True) |
10 | | -_T1 = TypeVar("_T1") |
11 | | -_T2 = TypeVar("_T2") |
12 | 11 | _K = TypeVar("_K") |
13 | 12 | _V = TypeVar("_V") |
14 | 13 | _P = ParamSpec("_P") |
15 | | -_Ts = TypeVarTuple("_Ts") |
16 | 14 |
|
17 | 15 | # The following protocols return "Any" instead of bool, since the comparison |
18 | 16 | # operators can be overloaded to return an arbitrary object. For example, |
@@ -92,40 +90,6 @@ def setitem(a: MutableSequence[_T], b: slice, c: Sequence[_T], /) -> None: ... |
92 | 90 | @overload |
93 | 91 | def setitem(a: MutableMapping[_K, _V], b: _K, c: _V, /) -> None: ... |
94 | 92 | def length_hint(obj: object, default: int = 0, /) -> int: ... |
95 | | -@final |
96 | | -class attrgetter(Generic[_T_co]): |
97 | | - @overload |
98 | | - def __new__(cls, attr: str, /) -> attrgetter[Any]: ... |
99 | | - @overload |
100 | | - def __new__(cls, attr: str, attr2: str, /) -> attrgetter[tuple[Any, Any]]: ... |
101 | | - @overload |
102 | | - def __new__(cls, attr: str, attr2: str, attr3: str, /) -> attrgetter[tuple[Any, Any, Any]]: ... |
103 | | - @overload |
104 | | - def __new__(cls, attr: str, attr2: str, attr3: str, attr4: str, /) -> attrgetter[tuple[Any, Any, Any, Any]]: ... |
105 | | - @overload |
106 | | - def __new__(cls, attr: str, /, *attrs: str) -> attrgetter[tuple[Any, ...]]: ... |
107 | | - def __call__(self, obj: Any, /) -> _T_co: ... |
108 | | - |
109 | | -@final |
110 | | -class itemgetter(Generic[_T_co]): |
111 | | - @overload |
112 | | - def __new__(cls, item: _T, /) -> itemgetter[_T]: ... |
113 | | - @overload |
114 | | - def __new__(cls, item1: _T1, item2: _T2, /, *items: Unpack[_Ts]) -> itemgetter[tuple[_T1, _T2, Unpack[_Ts]]]: ... |
115 | | - # __key: _KT_contra in SupportsGetItem seems to be causing variance issues, ie: |
116 | | - # TypeVar "_KT_contra@SupportsGetItem" is contravariant |
117 | | - # "tuple[int, int]" is incompatible with protocol "SupportsIndex" |
118 | | - # preventing [_T_co, ...] instead of [Any, ...] |
119 | | - # |
120 | | - # A suspected mypy issue prevents using [..., _T] instead of [..., Any] here. |
121 | | - # https://github.com/python/mypy/issues/14032 |
122 | | - def __call__(self, obj: SupportsGetItem[Any, Any]) -> Any: ... |
123 | | - |
124 | | -@final |
125 | | -class methodcaller: |
126 | | - def __init__(self, name: str, /, *args: Any, **kwargs: Any) -> None: ... |
127 | | - def __call__(self, obj: Any) -> Any: ... |
128 | | - |
129 | 93 | def iadd(a: Any, b: Any, /) -> Any: ... |
130 | 94 | def iand(a: Any, b: Any, /) -> Any: ... |
131 | 95 | def iconcat(a: Any, b: Any, /) -> Any: ... |
|
0 commit comments