diff --git a/stdlib/abc.pyi b/stdlib/abc.pyi index bf98d5364101..d2e35601b47e 100644 --- a/stdlib/abc.pyi +++ b/stdlib/abc.pyi @@ -1,13 +1,17 @@ from _typeshed import SupportsWrite -from typing import Any, Callable, Dict, Tuple, Type, TypeVar +from typing import Any, Callable, Generic, Tuple, Type, TypeVar +from typing_extensions import Concatenate, ParamSpec _T = TypeVar("_T") +_ClsT = TypeVar("_ClsT", bound=Type[Any]) +_P = ParamSpec("_P") +_R_co = TypeVar("_R_co", covariant=True) _FuncT = TypeVar("_FuncT", bound=Callable[..., Any]) # These definitions have special processing in mypy class ABCMeta(type): __abstractmethods__: frozenset[str] - def __init__(self, name: str, bases: Tuple[type, ...], namespace: Dict[str, Any]) -> None: ... + def __init__(self, name: str, bases: Tuple[type, ...], namespace: dict[str, Any]) -> None: ... def __instancecheck__(cls: ABCMeta, instance: Any) -> Any: ... def __subclasscheck__(cls: ABCMeta, subclass: Any) -> Any: ... def _dump_registry(cls: ABCMeta, file: SupportsWrite[str] | None = ...) -> None: ... @@ -15,12 +19,13 @@ class ABCMeta(type): def abstractmethod(funcobj: _FuncT) -> _FuncT: ... -class abstractproperty(property): ... +class abstractclassmethod(classmethod[_ClsT, _P, _R_co], Generic[_ClsT, _P, _R_co]): + def __init__(self, callable: Callable[Concatenate[_ClsT, _P], _R_co]) -> None: ... -# These two are deprecated and not supported by mypy -def abstractstaticmethod(callable: _FuncT) -> _FuncT: ... -def abstractclassmethod(callable: _FuncT) -> _FuncT: ... +class abstractstaticmethod(staticmethod[_FuncT], Generic[_FuncT]): + def __init__(self, callable: _FuncT) -> None: ... +class abstractproperty(property): ... class ABC(metaclass=ABCMeta): ... def get_cache_token() -> object: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 428139f422c5..11a5dce4d81d 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -16,6 +16,7 @@ from _typeshed import ( SupportsWrite, ) from ast import AST, mod +from collections.abc import Callable from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper from types import CodeType, TracebackType from typing import ( @@ -26,7 +27,6 @@ from typing import ( AsyncIterator, BinaryIO, ByteString, - Callable, Dict, FrozenSet, Generic, @@ -59,7 +59,7 @@ from typing import ( ValuesView, overload, ) -from typing_extensions import Literal, SupportsIndex, final +from typing_extensions import Concatenate, Literal, ParamSpec, SupportsIndex, final if sys.version_info >= (3, 9): from types import GenericAlias @@ -70,6 +70,7 @@ class _SupportsTrunc(Protocol): _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _T_contra = TypeVar("_T_contra", contravariant=True) +_R_co = TypeVar("_R_co", covariant=True) _KT = TypeVar("_KT") _VT = TypeVar("_VT") _S = TypeVar("_S") @@ -80,6 +81,9 @@ _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") _TT = TypeVar("_TT", bound="type") _TBE = TypeVar("_TBE", bound="BaseException") +_FuncT = TypeVar("_FuncT", bound=Callable[..., Any]) +_ClsT = TypeVar("_ClsT", bound=Type[Any]) +_P = ParamSpec("_P") class object: __doc__: Optional[str] @@ -109,19 +113,19 @@ class object: def __dir__(self) -> Iterable[str]: ... def __init_subclass__(cls) -> None: ... -class staticmethod(object): # Special, only valid as a decorator. - __func__: Callable[..., Any] +class staticmethod(Generic[_FuncT]): # Special, only valid as a decorator. + __func__: _FuncT __isabstractmethod__: bool - def __init__(self, f: Callable[..., Any]) -> None: ... + def __init__(self, __f: _FuncT) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... - def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ... + def __get__(self, obj: _T, type: Type[_T] | None = ...) -> _FuncT: ... -class classmethod(object): # Special, only valid as a decorator. - __func__: Callable[..., Any] +class classmethod(Generic[_ClsT, _P, _R_co]): # Special, only valid as a decorator. + __func__: Callable[Concatenate[_ClsT, _P], _R_co] __isabstractmethod__: bool - def __init__(self, f: Callable[..., Any]) -> None: ... + def __init__(self: classmethod[_ClsT, _P, _R_co], __f: Callable[Concatenate[_ClsT, _P], _R_co]) -> None: ... def __new__(cls: Type[_T], *args: Any, **kwargs: Any) -> _T: ... - def __get__(self, obj: _T, type: Optional[Type[_T]] = ...) -> Callable[..., Any]: ... + def __get__(self, obj: _T | None, type: Type[_T] | None = ...) -> Callable[_P, _R_co]: ... class type(object): __base__: type