Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve abc module and builtin function decorators (without ParamSpec) #5703

Merged
merged 25 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dd83c67
Improve abc module and builtin function decorators
srittau Jun 28, 2021
f99fc5f
Fix `__get__`
srittau Jun 28, 2021
f6bfdc9
Merge branch 'master' into abcmeta2
srittau Oct 4, 2021
e049258
Remove unused import
srittau Oct 4, 2021
91ae24d
Fix duplicate import
srittau Oct 4, 2021
c1d7c9c
Try copying __get__ to abstract{class,static}method
srittau Oct 4, 2021
060212b
Add __isabstractmethod__
srittau Oct 4, 2021
fe282c8
Add abstract*.__get__ to stubtest allowlist
srittau Oct 4, 2021
f82f04a
Remove abstract*.__get__ again
srittau Oct 4, 2021
8c59623
Merge branch 'master' into abcmeta2
srittau Dec 22, 2021
6f449b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 22, 2021
7bb6c28
Remove unused allowlist entries
srittau Dec 22, 2021
a0e344e
Remove unused type var
srittau Dec 22, 2021
a12c70e
Make abstractstaticmethod generic match staticmethod
srittau Dec 22, 2021
96bcd1e
Merge branch 'master' into abcmeta2
srittau Dec 23, 2021
1f54a2b
Merge branch 'master' into abcmeta2
srittau Jan 2, 2022
3c66c98
Merge branch 'master' into abcmeta2
srittau Jan 8, 2022
399dbd4
Update pytest
srittau Jan 8, 2022
b1eb4e3
Merge remote-tracking branch 'upstream/master' into abcmeta2
srittau Jan 8, 2022
7ac6c63
Merge branch 'master' into abcmeta2
JelleZijlstra Jan 9, 2022
0e60382
Update stdlib/abc.pyi
JelleZijlstra Jan 9, 2022
a3475b5
lowercase type
JelleZijlstra Jan 9, 2022
c28ea74
Merge branch 'master' into abcmeta2
srittau Feb 2, 2022
7c901cf
Fix merge errors
srittau Feb 2, 2022
2f8f6cd
Remove wrong comments
srittau Feb 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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