diff --git a/requirements-tests.txt b/requirements-tests.txt index 2287488766a9..fa6b3ef480eb 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,5 +1,5 @@ mypy==0.931 -pytype==2022.01.05; platform_system != "Windows" and python_version < "3.10" +pytype==2022.01.07; platform_system != "Windows" and python_version < "3.10" # must match .pre-commit-config.yaml black==22.1.0 flake8==4.0.1 diff --git a/stdlib/abc.pyi b/stdlib/abc.pyi index 33a53cc74c33..61b162bf8821 100644 --- a/stdlib/abc.pyi +++ b/stdlib/abc.pyi @@ -1,8 +1,11 @@ import sys from _typeshed import SupportsWrite -from typing import Any, Callable, TypeVar +from collections.abc import Callable +from typing import Any, Generic, TypeVar +from typing_extensions import Literal _T = TypeVar("_T") +_R_co = TypeVar("_R_co", covariant=True) _FuncT = TypeVar("_FuncT", bound=Callable[..., Any]) # These definitions have special processing in mypy @@ -16,12 +19,15 @@ class ABCMeta(type): def abstractmethod(funcobj: _FuncT) -> _FuncT: ... -class abstractproperty(property): ... +class abstractclassmethod(classmethod[_R_co], Generic[_R_co]): + __isabstractmethod__: Literal[True] + def __init__(self: abstractclassmethod[_R_co], callable: Callable[..., _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[_R_co], Generic[_R_co]): + __isabstractmethod__: Literal[True] + def __init__(self, callable: Callable[..., _R_co]) -> None: ... +class abstractproperty(property): ... class ABC(metaclass=ABCMeta): ... def get_cache_token() -> object: ... diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 81a7773bad04..a42cd04236db 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -22,6 +22,7 @@ from _typeshed import ( SupportsTrunc, SupportsWrite, ) +from collections.abc import Callable from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper from types import CodeType, TracebackType, _Cell from typing import ( @@ -30,7 +31,6 @@ from typing import ( Any, BinaryIO, ByteString, - Callable, Generic, Iterable, Iterator, @@ -61,6 +61,7 @@ if sys.version_info >= (3, 9): _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") @@ -69,7 +70,6 @@ _T2 = TypeVar("_T2") _T3 = TypeVar("_T3") _T4 = TypeVar("_T4") _T5 = TypeVar("_T5") -_R = TypeVar("_R") # Return-type TypeVar _SupportsNextT = TypeVar("_SupportsNextT", bound=SupportsNext[Any], covariant=True) _SupportsAnextT = TypeVar("_SupportsAnextT", bound=SupportsAnext[Any], covariant=True) @@ -112,26 +112,26 @@ class object: def __dir__(self) -> Iterable[str]: ... def __init_subclass__(cls) -> None: ... -class staticmethod(Generic[_R]): - __func__: Callable[..., _R] +class staticmethod(Generic[_R_co]): + __func__: Callable[..., _R_co] __isabstractmethod__: bool - def __init__(self: staticmethod[_R], __f: Callable[..., _R]) -> None: ... - def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R]: ... + def __init__(self: staticmethod[_R_co], __f: Callable[..., _R_co]) -> None: ... + def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R_co]: ... if sys.version_info >= (3, 10): __name__: str __qualname__: str - __wrapped__: Callable[..., _R] - def __call__(self, *args: Any, **kwargs: Any) -> _R: ... + __wrapped__: Callable[..., _R_co] + def __call__(self, *args: Any, **kwargs: Any) -> _R_co: ... -class classmethod(Generic[_R]): - __func__: Callable[..., _R] +class classmethod(Generic[_R_co]): + __func__: Callable[..., _R_co] __isabstractmethod__: bool - def __init__(self: classmethod[_R], __f: Callable[..., _R]) -> None: ... - def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R]: ... + def __init__(self: classmethod[_R_co], __f: Callable[..., _R_co]) -> None: ... + def __get__(self, __obj: _T, __type: type[_T] | None = ...) -> Callable[..., _R_co]: ... if sys.version_info >= (3, 10): __name__: str __qualname__: str - __wrapped__: Callable[..., _R] + __wrapped__: Callable[..., _R_co] class type: __base__: type diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index f244ecff7c52..343cda1b1e97 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -19,8 +19,6 @@ _csv.Dialect.__init__ # C __init__ signature is inaccurate _socket.* _threading_local.local.__new__ _weakref.ref.__call__ -abc.abstractclassmethod # Deprecated, unsupported by mypy, hard to fix. #6552 -abc.abstractstaticmethod # Deprecated, unsupported by mypy, hard to fix. #6552 abc.ABCMeta.__new__ # pytype wants the parameter named cls and not mcls _weakref.CallableProxyType.__getattr__ # Should have all attributes of proxy _weakref.ProxyType.__getattr__ # Should have all attributes of proxy