From e630fe8a21a43dcd17e9a8ed018646c1fcd5c81b Mon Sep 17 00:00:00 2001 From: laundmo Date: Mon, 4 Apr 2022 10:51:58 +0200 Subject: [PATCH 1/6] Add undocumented _mapping to MappingView etc. --- stdlib/_collections_abc.pyi | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/stdlib/_collections_abc.pyi b/stdlib/_collections_abc.pyi index bd8d35641b37..0db5a6182721 100644 --- a/stdlib/_collections_abc.pyi +++ b/stdlib/_collections_abc.pyi @@ -14,12 +14,12 @@ from typing import ( Generator as Generator, Generic, Hashable as Hashable, - ItemsView as ItemsView, + ItemsView as _ItemsView, Iterable as Iterable, Iterator as Iterator, - KeysView as KeysView, + KeysView as _KeysView, Mapping as Mapping, - MappingView as MappingView, + MappingView as _MappingView, MutableMapping as MutableMapping, MutableSequence as MutableSequence, MutableSet as MutableSet, @@ -27,7 +27,8 @@ from typing import ( Sequence as Sequence, Sized as Sized, TypeVar, - ValuesView as ValuesView, + ValuesView as _ValuesView, + Any as _Any, ) from typing_extensions import final @@ -63,19 +64,31 @@ _KT_co = TypeVar("_KT_co", covariant=True) # Key type covariant containers. _VT_co = TypeVar("_VT_co", covariant=True) # Value type covariant containers. @final -class dict_keys(KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented +class dict_keys(_KeysView[_KT_co], Generic[_KT_co, _VT_co]): # undocumented if sys.version_info >= (3, 10): @property def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ... @final -class dict_values(ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented +class dict_values(_ValuesView[_VT_co], Generic[_KT_co, _VT_co]): # undocumented if sys.version_info >= (3, 10): @property def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ... @final -class dict_items(ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocumented +class dict_items(_ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocumented if sys.version_info >= (3, 10): @property def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ... + +class MappingView(_MappingView): + _mapping: Mapping[_Any, _Any] # undocumented + +class KeysView(_KeysView[_KT_co], Generic[_KT_co, _VT_co]): + _mapping: Mapping[_KT_co, _VT_co] # undocumented + +class ValuesView(_KeysView[_VT_co], Generic[_KT_co, _VT_co]): + _mapping: Mapping[_KT_co, _VT_co] # undocumented + +class ItemsView(_ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): + _mapping: Mapping[_KT_co, _VT_co] # undocumented From 3b8ee8300eb68e71ebd1e170fc11704310c3cb19 Mon Sep 17 00:00:00 2001 From: laundmo Date: Mon, 4 Apr 2022 11:00:46 +0200 Subject: [PATCH 2/6] fixes Keys/Values views expecting more than 1 type --- stdlib/_collections_abc.pyi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stdlib/_collections_abc.pyi b/stdlib/_collections_abc.pyi index 0db5a6182721..185f85adc8b2 100644 --- a/stdlib/_collections_abc.pyi +++ b/stdlib/_collections_abc.pyi @@ -28,7 +28,7 @@ from typing import ( Sized as Sized, TypeVar, ValuesView as _ValuesView, - Any as _Any, + Any, ) from typing_extensions import final @@ -82,13 +82,13 @@ class dict_items(_ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): # undocu def mapping(self) -> MappingProxyType[_KT_co, _VT_co]: ... class MappingView(_MappingView): - _mapping: Mapping[_Any, _Any] # undocumented + _mapping: Mapping[Any, Any] # undocumented -class KeysView(_KeysView[_KT_co], Generic[_KT_co, _VT_co]): - _mapping: Mapping[_KT_co, _VT_co] # undocumented +class KeysView(_KeysView[_KT_co], Generic[_KT_co]): + _mapping: Mapping[_KT_co, Any] # undocumented -class ValuesView(_KeysView[_VT_co], Generic[_KT_co, _VT_co]): - _mapping: Mapping[_KT_co, _VT_co] # undocumented +class ValuesView(_ValuesView[_VT_co], Generic[_VT_co]): + _mapping: Mapping[Any, _VT_co] # undocumented class ItemsView(_ItemsView[_KT_co, _VT_co], Generic[_KT_co, _VT_co]): _mapping: Mapping[_KT_co, _VT_co] # undocumented From 5204b7c85efefe3bd91e43ccbfa4051ebcce162c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Apr 2022 09:12:52 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_collections_abc.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_collections_abc.pyi b/stdlib/_collections_abc.pyi index 185f85adc8b2..da4cb24cb5da 100644 --- a/stdlib/_collections_abc.pyi +++ b/stdlib/_collections_abc.pyi @@ -2,6 +2,7 @@ import sys from types import MappingProxyType from typing import ( AbstractSet as Set, + Any, AsyncGenerator as AsyncGenerator, AsyncIterable as AsyncIterable, AsyncIterator as AsyncIterator, @@ -28,7 +29,6 @@ from typing import ( Sized as Sized, TypeVar, ValuesView as _ValuesView, - Any, ) from typing_extensions import final From bb10b4c8fdd29ffd4e99760d6689f0b21f240762 Mon Sep 17 00:00:00 2001 From: laundmo Date: Mon, 4 Apr 2022 11:40:11 +0200 Subject: [PATCH 4/6] Delete allowlist entries --- tests/stubtest_allowlists/py310.txt | 3 --- tests/stubtest_allowlists/py38.txt | 3 --- tests/stubtest_allowlists/py39.txt | 3 --- 3 files changed, 9 deletions(-) diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 994cd25a0095..e7f04ba4a332 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -3,9 +3,6 @@ _collections_abc.AsyncGenerator.ag_await _collections_abc.AsyncGenerator.ag_code _collections_abc.AsyncGenerator.ag_frame _collections_abc.AsyncGenerator.ag_running -_collections_abc.ItemsView.__reversed__ -_collections_abc.KeysView.__reversed__ -_collections_abc.ValuesView.__reversed__ # These are not positional-only at runtime, but we treat them # as positional-only to match dict. diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index f8466db95d3a..7c76185062bf 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -2,9 +2,6 @@ _collections_abc.AsyncGenerator.ag_await _collections_abc.AsyncGenerator.ag_code _collections_abc.AsyncGenerator.ag_frame _collections_abc.AsyncGenerator.ag_running -_collections_abc.ItemsView.__reversed__ -_collections_abc.KeysView.__reversed__ -_collections_abc.ValuesView.__reversed__ _dummy_threading ast.Bytes.__new__ ast.Ellipsis.__new__ diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index f09e5171a52a..331414933fce 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -3,9 +3,6 @@ _collections_abc.AsyncGenerator.ag_await _collections_abc.AsyncGenerator.ag_code _collections_abc.AsyncGenerator.ag_frame _collections_abc.AsyncGenerator.ag_running -_collections_abc.ItemsView.__reversed__ -_collections_abc.KeysView.__reversed__ -_collections_abc.ValuesView.__reversed__ _weakref.ProxyType.__reversed__ # Doesn't really exist ast.Bytes.__new__ ast.Ellipsis.__new__ From 80f9e8c04663e35f072388d0b6508a86a17b549d Mon Sep 17 00:00:00 2001 From: laundmo Date: Mon, 4 Apr 2022 11:45:23 +0200 Subject: [PATCH 5/6] delete more allowlist --- tests/stubtest_allowlists/py39.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/stubtest_allowlists/py39.txt b/tests/stubtest_allowlists/py39.txt index 331414933fce..ec482002bcb5 100644 --- a/tests/stubtest_allowlists/py39.txt +++ b/tests/stubtest_allowlists/py39.txt @@ -30,9 +30,6 @@ collections.AsyncGenerator.ag_frame collections.AsyncGenerator.ag_running collections.Callable collections.Mapping.__reversed__ # Set to None at runtime for a better error message -collections.ItemsView.__reversed__ -collections.KeysView.__reversed__ -collections.ValuesView.__reversed__ # Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414. collections.Set.__rand__ collections.Set.__ror__ From 89f9ff9a96e11aa796b566c9e4495090e482c3ea Mon Sep 17 00:00:00 2001 From: laundmo Date: Mon, 4 Apr 2022 11:53:03 +0200 Subject: [PATCH 6/6] delete even more allowlist --- tests/stubtest_allowlists/py38.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index 7c76185062bf..2579a5101879 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -25,9 +25,6 @@ collections.AsyncGenerator.ag_code collections.AsyncGenerator.ag_frame collections.AsyncGenerator.ag_running collections.Callable -collections.ItemsView.__reversed__ -collections.KeysView.__reversed__ -collections.ValuesView.__reversed__ collections.Mapping.__reversed__ # Set to None at runtime for a better error message # Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414. collections.Set.__rand__