@@ -2,14 +2,17 @@ import sys
22from _typeshed import SupportsGetItem
33from collections .abc import Callable , Container , Iterable , MutableMapping , MutableSequence , Sequence
44from typing import Any , AnyStr , Generic , Protocol , SupportsAbs , TypeVar , overload
5- from typing_extensions import ParamSpec , SupportsIndex , TypeAlias , final
5+ from typing_extensions import ParamSpec , SupportsIndex , TypeAlias , TypeVarTuple , Unpack , final
66
77_R = TypeVar ("_R" )
88_T = TypeVar ("_T" )
99_T_co = TypeVar ("_T_co" , covariant = True )
10+ _T1 = TypeVar ("_T1" )
11+ _T2 = TypeVar ("_T2" )
1012_K = TypeVar ("_K" )
1113_V = TypeVar ("_V" )
1214_P = ParamSpec ("_P" )
15+ _Ts = TypeVarTuple ("_Ts" )
1316
1417# The following protocols return "Any" instead of bool, since the comparison
1518# operators can be overloaded to return an arbitrary object. For example,
@@ -105,22 +108,10 @@ class attrgetter(Generic[_T_co]):
105108
106109@final
107110class itemgetter (Generic [_T_co ]):
108- # mypy lacks support for PEP 646 https://github.com/python/mypy/issues/12280
109- # So we have to define all of these overloads to simulate unpacking the arguments
110111 @overload
111- def __new__ (cls , item : _T_co ) -> itemgetter [_T_co ]: ...
112+ def __new__ (cls , __item : _T ) -> itemgetter [_T ]: ...
112113 @overload
113- def __new__ (cls , item : _T_co , __item2 : _T_co ) -> itemgetter [tuple [_T_co , _T_co ]]: ...
114- @overload
115- def __new__ (cls , item : _T_co , __item2 : _T_co , __item3 : _T_co ) -> itemgetter [tuple [_T_co , _T_co , _T_co ]]: ...
116- @overload
117- def __new__ (
118- cls , item : _T_co , __item2 : _T_co , __item3 : _T_co , __item4 : _T_co
119- ) -> itemgetter [tuple [_T_co , _T_co , _T_co , _T_co ]]: ...
120- @overload
121- def __new__ (
122- cls , item : _T_co , __item2 : _T_co , __item3 : _T_co , __item4 : _T_co , * items : _T_co
123- ) -> itemgetter [tuple [_T_co , ...]]: ...
114+ def __new__ (cls , __item1 : _T1 , __item2 : _T2 , * items : Unpack [_Ts ]) -> itemgetter [tuple [_T1 , _T2 , Unpack [_Ts ]]]: ...
124115 # __key: _KT_contra in SupportsGetItem seems to be causing variance issues, ie:
125116 # TypeVar "_KT_contra@SupportsGetItem" is contravariant
126117 # "tuple[int, int]" is incompatible with protocol "SupportsIndex"
0 commit comments