Skip to content

Commit 28dd6c1

Browse files
authored
Use ParamSpec for classmethod and staticmethod (#9771)
1 parent 5187054 commit 28dd6c1

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

stdlib/abc.pyi

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import _typeshed
22
import sys
33
from _typeshed import SupportsWrite
44
from collections.abc import Callable
5-
from typing import Any, Generic, TypeVar
6-
from typing_extensions import Literal
5+
from typing import Any, TypeVar
6+
from typing_extensions import Concatenate, Literal, ParamSpec
77

88
_T = TypeVar("_T")
99
_R_co = TypeVar("_R_co", covariant=True)
1010
_FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
11+
_P = ParamSpec("_P")
1112

1213
# These definitions have special processing in mypy
1314
class ABCMeta(type):
@@ -28,13 +29,13 @@ class ABCMeta(type):
2829

2930
def abstractmethod(funcobj: _FuncT) -> _FuncT: ...
3031

31-
class abstractclassmethod(classmethod[_R_co], Generic[_R_co]):
32+
class abstractclassmethod(classmethod[_T, _P, _R_co]):
3233
__isabstractmethod__: Literal[True]
33-
def __init__(self: abstractclassmethod[_R_co], callable: Callable[..., _R_co]) -> None: ...
34+
def __init__(self, callable: Callable[Concatenate[_T, _P], _R_co]) -> None: ...
3435

35-
class abstractstaticmethod(staticmethod[_R_co], Generic[_R_co]):
36+
class abstractstaticmethod(staticmethod[_P, _R_co]):
3637
__isabstractmethod__: Literal[True]
37-
def __init__(self, callable: Callable[..., _R_co]) -> None: ...
38+
def __init__(self, callable: Callable[_P, _R_co]) -> None: ...
3839

3940
class abstractproperty(property):
4041
__isabstractmethod__: Literal[True]

stdlib/builtins.pyi

+13-12
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ from typing import ( # noqa: Y022
5454
overload,
5555
type_check_only,
5656
)
57-
from typing_extensions import Literal, LiteralString, Self, SupportsIndex, TypeAlias, TypeGuard, final
57+
from typing_extensions import Concatenate, Literal, LiteralString, ParamSpec, Self, SupportsIndex, TypeAlias, TypeGuard, final
5858

5959
if sys.version_info >= (3, 9):
6060
from types import GenericAlias
@@ -75,6 +75,7 @@ _SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=Tr
7575
_SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True)
7676
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
7777
_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
78+
_P = ParamSpec("_P")
7879

7980
class object:
8081
__doc__: str | None
@@ -113,32 +114,32 @@ class object:
113114
@classmethod
114115
def __subclasshook__(cls, __subclass: type) -> bool: ...
115116

116-
class staticmethod(Generic[_R_co]):
117+
class staticmethod(Generic[_P, _R_co]):
117118
@property
118-
def __func__(self) -> Callable[..., _R_co]: ...
119+
def __func__(self) -> Callable[_P, _R_co]: ...
119120
@property
120121
def __isabstractmethod__(self) -> bool: ...
121-
def __init__(self: staticmethod[_R_co], __f: Callable[..., _R_co]) -> None: ...
122-
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[..., _R_co]: ...
122+
def __init__(self, __f: Callable[_P, _R_co]) -> None: ...
123+
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[_P, _R_co]: ...
123124
if sys.version_info >= (3, 10):
124125
__name__: str
125126
__qualname__: str
126127
@property
127-
def __wrapped__(self) -> Callable[..., _R_co]: ...
128-
def __call__(self, *args: Any, **kwargs: Any) -> _R_co: ...
128+
def __wrapped__(self) -> Callable[_P, _R_co]: ...
129+
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ...
129130

130-
class classmethod(Generic[_R_co]):
131+
class classmethod(Generic[_T, _P, _R_co]):
131132
@property
132-
def __func__(self) -> Callable[..., _R_co]: ...
133+
def __func__(self) -> Callable[Concatenate[_T, _P], _R_co]: ...
133134
@property
134135
def __isabstractmethod__(self) -> bool: ...
135-
def __init__(self: classmethod[_R_co], __f: Callable[..., _R_co]) -> None: ...
136-
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[..., _R_co]: ...
136+
def __init__(self, __f: Callable[Concatenate[_T, _P], _R_co]) -> None: ...
137+
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[_P, _R_co]: ...
137138
if sys.version_info >= (3, 10):
138139
__name__: str
139140
__qualname__: str
140141
@property
141-
def __wrapped__(self) -> Callable[..., _R_co]: ...
142+
def __wrapped__(self) -> Callable[Concatenate[_T, _P], _R_co]: ...
142143

143144
class type:
144145
@property

0 commit comments

Comments
 (0)