Use ParamSpec for classmethod and staticmethod (#9771)

This commit is contained in:
Alex Waygood
2023-03-14 09:59:17 +00:00
committed by GitHub
parent 51870544db
commit 28dd6c1a2e
2 changed files with 20 additions and 18 deletions

View File

@@ -2,12 +2,13 @@ import _typeshed
import sys
from _typeshed import SupportsWrite
from collections.abc import Callable
from typing import Any, Generic, TypeVar
from typing_extensions import Literal
from typing import Any, TypeVar
from typing_extensions import Concatenate, Literal, ParamSpec
_T = TypeVar("_T")
_R_co = TypeVar("_R_co", covariant=True)
_FuncT = TypeVar("_FuncT", bound=Callable[..., Any])
_P = ParamSpec("_P")
# These definitions have special processing in mypy
class ABCMeta(type):
@@ -28,13 +29,13 @@ class ABCMeta(type):
def abstractmethod(funcobj: _FuncT) -> _FuncT: ...
class abstractclassmethod(classmethod[_R_co], Generic[_R_co]):
class abstractclassmethod(classmethod[_T, _P, _R_co]):
__isabstractmethod__: Literal[True]
def __init__(self: abstractclassmethod[_R_co], callable: Callable[..., _R_co]) -> None: ...
def __init__(self, callable: Callable[Concatenate[_T, _P], _R_co]) -> None: ...
class abstractstaticmethod(staticmethod[_R_co], Generic[_R_co]):
class abstractstaticmethod(staticmethod[_P, _R_co]):
__isabstractmethod__: Literal[True]
def __init__(self, callable: Callable[..., _R_co]) -> None: ...
def __init__(self, callable: Callable[_P, _R_co]) -> None: ...
class abstractproperty(property):
__isabstractmethod__: Literal[True]

View File

@@ -54,7 +54,7 @@ from typing import ( # noqa: Y022
overload,
type_check_only,
)
from typing_extensions import Literal, LiteralString, Self, SupportsIndex, TypeAlias, TypeGuard, final
from typing_extensions import Concatenate, Literal, LiteralString, ParamSpec, Self, SupportsIndex, TypeAlias, TypeGuard, final
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -75,6 +75,7 @@ _SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=Tr
_SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True)
_AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
_AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
_P = ParamSpec("_P")
class object:
__doc__: str | None
@@ -113,32 +114,32 @@ class object:
@classmethod
def __subclasshook__(cls, __subclass: type) -> bool: ...
class staticmethod(Generic[_R_co]):
class staticmethod(Generic[_P, _R_co]):
@property
def __func__(self) -> Callable[..., _R_co]: ...
def __func__(self) -> Callable[_P, _R_co]: ...
@property
def __isabstractmethod__(self) -> bool: ...
def __init__(self: staticmethod[_R_co], __f: Callable[..., _R_co]) -> None: ...
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[..., _R_co]: ...
def __init__(self, __f: Callable[_P, _R_co]) -> None: ...
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[_P, _R_co]: ...
if sys.version_info >= (3, 10):
__name__: str
__qualname__: str
@property
def __wrapped__(self) -> Callable[..., _R_co]: ...
def __call__(self, *args: Any, **kwargs: Any) -> _R_co: ...
def __wrapped__(self) -> Callable[_P, _R_co]: ...
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ...
class classmethod(Generic[_R_co]):
class classmethod(Generic[_T, _P, _R_co]):
@property
def __func__(self) -> Callable[..., _R_co]: ...
def __func__(self) -> Callable[Concatenate[_T, _P], _R_co]: ...
@property
def __isabstractmethod__(self) -> bool: ...
def __init__(self: classmethod[_R_co], __f: Callable[..., _R_co]) -> None: ...
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[..., _R_co]: ...
def __init__(self, __f: Callable[Concatenate[_T, _P], _R_co]) -> None: ...
def __get__(self, __instance: _T, __owner: type[_T] | None = None) -> Callable[_P, _R_co]: ...
if sys.version_info >= (3, 10):
__name__: str
__qualname__: str
@property
def __wrapped__(self) -> Callable[..., _R_co]: ...
def __wrapped__(self) -> Callable[Concatenate[_T, _P], _R_co]: ...
class type:
@property