Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02556fb

Browse files
authored
bpo-32467: Let collections.abc.ValuesView inherit from Collection (#5152)
1 parent 782d6fe commit 02556fb

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

Doc/library/collections.abc.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ ABC Inherits from Abstract Methods Mixin
8787
:class:`Set` ``__iter__``
8888
:class:`KeysView` :class:`MappingView`, ``__contains__``,
8989
:class:`Set` ``__iter__``
90-
:class:`ValuesView` :class:`MappingView` ``__contains__``, ``__iter__``
90+
:class:`ValuesView` :class:`MappingView`, ``__contains__``, ``__iter__``
91+
:class:`Collection`
9192
:class:`Awaitable` ``__await__``
9293
:class:`Coroutine` :class:`Awaitable` ``send``, ``throw`` ``close``
9394
:class:`AsyncIterable` ``__aiter__``

Lib/_collections_abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def __iter__(self):
746746
ItemsView.register(dict_items)
747747

748748

749-
class ValuesView(MappingView):
749+
class ValuesView(MappingView, Collection):
750750

751751
__slots__ = ()
752752

Lib/test/test_collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,13 +843,13 @@ def test_Collection(self):
843843
self.assertFalse(issubclass(type(x), Collection), repr(type(x)))
844844
# Check some non-collection iterables
845845
non_col_iterables = [_test_gen(), iter(b''), iter(bytearray()),
846-
(x for x in []), dict().values()]
846+
(x for x in [])]
847847
for x in non_col_iterables:
848848
self.assertNotIsInstance(x, Collection)
849849
self.assertFalse(issubclass(type(x), Collection), repr(type(x)))
850850
# Check some collections
851851
samples = [set(), frozenset(), dict(), bytes(), str(), tuple(),
852-
list(), dict().keys(), dict().items()]
852+
list(), dict().keys(), dict().items(), dict().values()]
853853
for x in samples:
854854
self.assertIsInstance(x, Collection)
855855
self.assertTrue(issubclass(type(x), Collection), repr(type(x)))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
collections.abc.ValuesView now inherits from collections.abc.Collection.

0 commit comments

Comments
 (0)