From 7df48a8b066bf1be0f363570925d14740bd5ba8f Mon Sep 17 00:00:00 2001 From: Joshua Bronson Date: Sat, 10 Dec 2022 11:47:14 -0500 Subject: [PATCH 1/5] Revert "`Collection` is `Sized` (#8977)" This reverts commit 5bbba5d008ffe6f26ffe4fb9e7c7b3e0765a2b0a. --- stdlib/builtins.pyi | 2 +- stdlib/typing.pyi | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index df74a00a42bc..12b2069c636f 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -804,7 +804,7 @@ class bytearray(MutableSequence[int], ByteString): def __alloc__(self) -> int: ... @final -class memoryview(Sequence[int]): +class memoryview(Sized, Sequence[int]): @property def format(self) -> str: ... @property diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index cc27ae7dbda2..3c577ce15270 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -452,7 +452,10 @@ class Container(Protocol[_T_co]): def __contains__(self, __x: object) -> bool: ... @runtime_checkable -class Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ... +class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]): + # Implement Sized (but don't have it as a base class). + @abstractmethod + def __len__(self) -> int: ... class Sequence(Collection[_T_co], Reversible[_T_co], Generic[_T_co]): @overload From c9ae4f93739edbeb2dc5ca2b1305ed2c2e500528 Mon Sep 17 00:00:00 2001 From: Joshua Bronson Date: Sat, 10 Dec 2022 11:47:48 -0500 Subject: [PATCH 2/5] Revert "typing: remove metaclass from Sized (#9058)" This reverts commit a3ce51209544d64d03018b3927051375f1bebe82. --- stdlib/typing.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index 3c577ce15270..71018003b6d9 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -325,7 +325,7 @@ class SupportsRound(Protocol[_T_co]): def __round__(self, __ndigits: int) -> _T_co: ... @runtime_checkable -class Sized(Protocol): +class Sized(Protocol, metaclass=ABCMeta): @abstractmethod def __len__(self) -> int: ... From 69e36c1b988e54e129402973a6e23c508ed615a2 Mon Sep 17 00:00:00 2001 From: Joshua Bronson Date: Sat, 10 Dec 2022 11:58:39 -0500 Subject: [PATCH 3/5] Add regression test for issue 9296. --- .../typing/check_regression_issue_9296.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test_cases/stdlib/typing/check_regression_issue_9296.py diff --git a/test_cases/stdlib/typing/check_regression_issue_9296.py b/test_cases/stdlib/typing/check_regression_issue_9296.py new file mode 100644 index 000000000000..1ad6311847d8 --- /dev/null +++ b/test_cases/stdlib/typing/check_regression_issue_9296.py @@ -0,0 +1,18 @@ +from __future__ import annotations + +import typing as t + + +KT = t.TypeVar("KT") + + +class MyKeysView(t.KeysView[KT]): + pass + + +d: dict[t.Any, t.Any] = {} +dict_keys = type(d.keys()) + +# This should not cause an error like `Member "register" is unknown`: +MyKeysView.register(dict_keys) + From 17a8e5f9523fbf1f451c2e142d9faf952695f82a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 10 Dec 2022 17:40:36 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- test_cases/stdlib/typing/check_regression_issue_9296.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test_cases/stdlib/typing/check_regression_issue_9296.py b/test_cases/stdlib/typing/check_regression_issue_9296.py index 1ad6311847d8..34c5631aeb1a 100644 --- a/test_cases/stdlib/typing/check_regression_issue_9296.py +++ b/test_cases/stdlib/typing/check_regression_issue_9296.py @@ -2,7 +2,6 @@ import typing as t - KT = t.TypeVar("KT") @@ -15,4 +14,3 @@ class MyKeysView(t.KeysView[KT]): # This should not cause an error like `Member "register" is unknown`: MyKeysView.register(dict_keys) - From 8a329ba6eb3e393d376c6d1ab62c9a96a805ec68 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 10 Dec 2022 09:56:50 -0800 Subject: [PATCH 5/5] Update stdlib/builtins.pyi --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 12b2069c636f..df74a00a42bc 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -804,7 +804,7 @@ class bytearray(MutableSequence[int], ByteString): def __alloc__(self) -> int: ... @final -class memoryview(Sized, Sequence[int]): +class memoryview(Sequence[int]): @property def format(self) -> str: ... @property