From 11498366a028f8235fe236cc8e6eaf5abfef21d0 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Feb 2022 18:28:56 +0000 Subject: [PATCH 1/7] Add missing descriptor methods in `dataclasses` and `functools` --- stdlib/dataclasses.pyi | 1 + stdlib/functools.pyi | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/dataclasses.pyi b/stdlib/dataclasses.pyi index 4a8f8134bea4..2988e42b4a3e 100644 --- a/stdlib/dataclasses.pyi +++ b/stdlib/dataclasses.pyi @@ -111,6 +111,7 @@ class Field(Generic[_T]): compare: bool, metadata: Mapping[Any, Any], ) -> None: ... + def __set_name__(self, owner: type, name: str) -> None: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index ddbbfa3d57b9..f2b8d9a2887b 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -105,7 +105,7 @@ if sys.version_info >= (3, 8): def register(self, cls: Callable[..., _T], method: None = ...) -> Callable[..., _T]: ... @overload def register(self, cls: type[Any], method: Callable[..., _T]) -> Callable[..., _T]: ... - def __call__(self, *args: Any, **kwargs: Any) -> _T: ... + def __get__(self, obj: _S, cls: type[_S] | None = ...) -> Callable[..., _T]: ... class cached_property(Generic[_T]): func: Callable[[Any], _T] From 60f882eb7fcb411626285ad627ef779581399131 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 18:31:05 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/dataclasses.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/dataclasses.pyi b/stdlib/dataclasses.pyi index 2988e42b4a3e..139c727be51e 100644 --- a/stdlib/dataclasses.pyi +++ b/stdlib/dataclasses.pyi @@ -111,6 +111,7 @@ class Field(Generic[_T]): compare: bool, metadata: Mapping[Any, Any], ) -> None: ... + def __set_name__(self, owner: type, name: str) -> None: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... From 61c02ea72855360de4d9e42380ba9d94e7255f5e Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Feb 2022 18:32:49 +0000 Subject: [PATCH 3/7] Update dataclasses.pyi --- stdlib/dataclasses.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/dataclasses.pyi b/stdlib/dataclasses.pyi index 139c727be51e..370c80cc5cde 100644 --- a/stdlib/dataclasses.pyi +++ b/stdlib/dataclasses.pyi @@ -112,7 +112,7 @@ class Field(Generic[_T]): metadata: Mapping[Any, Any], ) -> None: ... - def __set_name__(self, owner: type, name: str) -> None: ... + def __set_name__(self, owner: Type[Any], name: str) -> None: ... if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any) -> GenericAlias: ... From d9179a80da72f1a6d2afac51c0ab40f1c8667bdf Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Feb 2022 18:36:00 +0000 Subject: [PATCH 4/7] Remove allowlist entries --- tests/stubtest_allowlists/py310.txt | 1 - tests/stubtest_allowlists/py38.txt | 1 - tests/stubtest_allowlists/py39.txt | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index d9ba1aeb11d1..9174db621677 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -51,7 +51,6 @@ enum.Enum._generate_next_value_ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 functools.partialmethod.__get__ -functools.singledispatchmethod.__call__ gettext.install gettext.translation hashlib.sha3_\d+ # Can be a class or a built-in function diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index 46bb16c0d23c..72f24a35b448 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -38,7 +38,6 @@ enum.Enum._generate_next_value_ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 functools.partialmethod.__get__ -functools.singledispatchmethod.__call__ # A lie to reflect that the descriptor get returns a callable gettext.install # codeset default value is ['unspecified'] so can't be specified gettext.translation # codeset default value is ['unspecified'] so can't be specified hmac.new # Stub is a white lie; see comments in the stub diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index 92d763db8458..1e04649ef3ac 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -37,7 +37,6 @@ enum.Enum._generate_next_value_ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 functools.partialmethod.__get__ -functools.singledispatchmethod.__call__ gettext.install gettext.translation hashlib.sha3_\d+ From 53856853b8eecf6cddf259f62e8fb55d2e866e6f Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Feb 2022 18:39:55 +0000 Subject: [PATCH 5/7] Fix `partialmethod.__get__` while we're here --- stdlib/functools.pyi | 2 +- tests/stubtest_allowlists/py310.txt | 1 - tests/stubtest_allowlists/py38.txt | 1 - tests/stubtest_allowlists/py39.txt | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index f2b8d9a2887b..57d8f376f9fb 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -69,7 +69,7 @@ class partialmethod(Generic[_T]): def __init__(self, __func: Callable[..., _T], *args: Any, **keywords: Any) -> None: ... @overload def __init__(self, __func: _Descriptor, *args: Any, **keywords: Any) -> None: ... - def __get__(self, obj: Any, cls: type[Any]) -> Callable[..., _T]: ... + def __get__(self, obj: Any, cls: type[Any] | None = ...) -> Callable[..., _T]: ... @property def __isabstractmethod__(self) -> bool: ... if sys.version_info >= (3, 9): diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 9174db621677..bd5ae6852946 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -50,7 +50,6 @@ dataclasses.KW_ONLY enum.Enum._generate_next_value_ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 -functools.partialmethod.__get__ gettext.install gettext.translation hashlib.sha3_\d+ # Can be a class or a built-in function diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index 72f24a35b448..ab417eb3e705 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -37,7 +37,6 @@ dummy_threading.local.__new__ enum.Enum._generate_next_value_ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 -functools.partialmethod.__get__ gettext.install # codeset default value is ['unspecified'] so can't be specified gettext.translation # codeset default value is ['unspecified'] so can't be specified hmac.new # Stub is a white lie; see comments in the stub diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index 1e04649ef3ac..c0e648aed349 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -36,7 +36,6 @@ dataclasses.field enum.Enum._generate_next_value_ fractions.Fraction.__new__ # overload is too complicated for stubtest to resolve ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally undocumented, intentionally missing from typeshed. #6154 -functools.partialmethod.__get__ gettext.install gettext.translation hashlib.sha3_\d+ From fd8749a96921712f6baedd7eda037702322e6aed Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Feb 2022 18:43:41 +0000 Subject: [PATCH 6/7] Actually fix `partialmethod.__get__` --- stdlib/functools.pyi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index 57d8f376f9fb..ede5c11c4f58 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -69,7 +69,10 @@ class partialmethod(Generic[_T]): def __init__(self, __func: Callable[..., _T], *args: Any, **keywords: Any) -> None: ... @overload def __init__(self, __func: _Descriptor, *args: Any, **keywords: Any) -> None: ... - def __get__(self, obj: Any, cls: type[Any] | None = ...) -> Callable[..., _T]: ... + if sys.version_info >= (3, 8): + def __get__(self, obj: Any, cls: type[Any] | None = ...) -> Callable[..., _T]: ... + else: + def __get__(self, obj: Any, cls: type[Any] | None) -> Callable[..., _T]: ... @property def __isabstractmethod__(self) -> bool: ... if sys.version_info >= (3, 9): From 5c91fd86f393a97ae95ada2d9928db2b602173be Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 14 Feb 2022 18:45:32 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/functools.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/functools.pyi b/stdlib/functools.pyi index ede5c11c4f58..7f230b0b81e0 100644 --- a/stdlib/functools.pyi +++ b/stdlib/functools.pyi @@ -73,6 +73,7 @@ class partialmethod(Generic[_T]): def __get__(self, obj: Any, cls: type[Any] | None = ...) -> Callable[..., _T]: ... else: def __get__(self, obj: Any, cls: type[Any] | None) -> Callable[..., _T]: ... + @property def __isabstractmethod__(self) -> bool: ... if sys.version_info >= (3, 9):