Skip to content

Commit 16a76a6

Browse files
authored
Make staticmethod/classmethod generic in their return type (#6285)
1 parent 4b3a8a8 commit 16a76a6

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

stdlib/builtins.pyi

+12-11
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ _T4 = TypeVar("_T4")
8383
_T5 = TypeVar("_T5")
8484
_TT = TypeVar("_TT", bound="type")
8585
_TBE = TypeVar("_TBE", bound="BaseException")
86+
_R = TypeVar("_R") # Return-type TypeVar
8687

8788
class object:
8889
__doc__: str | None
@@ -115,28 +116,28 @@ class object:
115116
def __dir__(self) -> Iterable[str]: ...
116117
def __init_subclass__(cls) -> None: ...
117118

118-
class staticmethod(object): # Special, only valid as a decorator.
119-
__func__: Callable[..., Any]
119+
class staticmethod(Generic[_R]): # Special, only valid as a decorator.
120+
__func__: Callable[..., _R]
120121
__isabstractmethod__: bool
121-
def __init__(self, __f: Callable[..., Any]) -> None: ...
122+
def __init__(self: staticmethod[_R], __f: Callable[..., _R]) -> None: ...
122123
def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ...
123-
def __get__(self, __obj: _T, __type: Type[_T] | None = ...) -> Callable[..., Any]: ...
124+
def __get__(self, __obj: _T, __type: Type[_T] | None = ...) -> Callable[..., _R]: ...
124125
if sys.version_info >= (3, 10):
125126
__name__: str
126127
__qualname__: str
127-
__wrapped__: Callable[..., Any]
128-
def __call__(self, *args: Any, **kwargs: Any) -> Any: ...
128+
__wrapped__: Callable[..., _R]
129+
def __call__(self, *args: Any, **kwargs: Any) -> _R: ...
129130

130-
class classmethod(object): # Special, only valid as a decorator.
131-
__func__: Callable[..., Any]
131+
class classmethod(Generic[_R]): # Special, only valid as a decorator.
132+
__func__: Callable[..., _R]
132133
__isabstractmethod__: bool
133-
def __init__(self, __f: Callable[..., Any]) -> None: ...
134+
def __init__(self: classmethod[_R], __f: Callable[..., _R]) -> None: ...
134135
def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ...
135-
def __get__(self, __obj: _T, __type: Type[_T] | None = ...) -> Callable[..., Any]: ...
136+
def __get__(self, __obj: _T, __type: Type[_T] | None = ...) -> Callable[..., _R]: ...
136137
if sys.version_info >= (3, 10):
137138
__name__: str
138139
__qualname__: str
139-
__wrapped__: Callable[..., Any]
140+
__wrapped__: Callable[..., _R]
140141

141142
class type(object):
142143
__base__: type

0 commit comments

Comments
 (0)