Skip to content

Commit

Permalink
Improve abc module and builtin function decorators (#5703)
Browse files Browse the repository at this point in the history
  • Loading branch information
srittau authored Feb 2, 2022
1 parent 584336a commit 2dc53ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 11 additions & 5 deletions stdlib/abc.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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: ...
Expand Down
26 changes: 13 additions & 13 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -30,7 +31,6 @@ from typing import (
Any,
BinaryIO,
ByteString,
Callable,
Generic,
Iterable,
Iterator,
Expand Down Expand Up @@ -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")
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/stubtest_allowlists/py3_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2dc53ca

Please sign in to comment.