@@ -53,14 +53,16 @@ from _operator import (
5353 xor as xor ,
5454)
5555from _typeshed import SupportsGetItem
56- from typing import Any , Generic , TypeVar , final , overload
56+ from typing import Any , Generic , ParamSpec , TypeVar , final , overload
5757from typing_extensions import Self , TypeVarTuple , Unpack
5858
5959_T = TypeVar ("_T" )
6060_T_co = TypeVar ("_T_co" , covariant = True )
6161_T1 = TypeVar ("_T1" )
6262_T2 = TypeVar ("_T2" )
6363_Ts = TypeVarTuple ("_Ts" )
64+ _P = ParamSpec ("_P" , default = ...)
65+ _R = TypeVar ("_R" , default = Any )
6466
6567__all__ = [
6668 "abs" ,
@@ -182,6 +184,8 @@ if sys.version_info >= (3, 11):
182184# them here.
183185@final
184186class attrgetter (Generic [_T_co ]):
187+ # We can't determine the type of the attribute(s) being accessed statucally,
188+ # so we have to use Any for the return type.
185189 @overload
186190 def __new__ (cls , attr : str , / ) -> attrgetter [Any ]: ...
187191 @overload
@@ -192,6 +196,8 @@ class attrgetter(Generic[_T_co]):
192196 def __new__ (cls , attr : str , attr2 : str , attr3 : str , attr4 : str , / ) -> attrgetter [tuple [Any , Any , Any , Any ]]: ...
193197 @overload
194198 def __new__ (cls , attr : str , / , * attrs : str ) -> attrgetter [tuple [Any , ...]]: ...
199+ # obj needs to have the named attribute(s) with the correct type.
200+ # Unfortunately, we can't check that statically, so we need to use Any.
195201 def __call__ (self , obj : Any , / ) -> _T_co : ...
196202
197203@final
@@ -212,6 +218,8 @@ class itemgetter(Generic[_T_co]):
212218 def __call__ (self , obj : SupportsGetItem [Any , Any ]) -> Any : ...
213219
214220@final
215- class methodcaller :
216- def __new__ (cls , name : str , / , * args : Any , ** kwargs : Any ) -> Self : ...
217- def __call__ (self , obj : Any ) -> Any : ...
221+ class methodcaller (Generic [_P , _R ]):
222+ def __new__ (cls , name : str , / , * args : _P .args , ** kwargs : _P .kwargs ) -> Self : ...
223+ # obj needs to have the named method with the correct signature.
224+ # Unfortunately, we can't check that statically, so we need to use Any.
225+ def __call__ (self , obj : Any ) -> _R : ...
0 commit comments