From 02556fbade5e1e864dd09d5768a8dbbf5b3a0dac Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 11 Jan 2018 21:53:49 -0800 Subject: bpo-32467: Let collections.abc.ValuesView inherit from Collection (#5152) --- Doc/library/collections.abc.rst | 3 ++- Lib/_collections_abc.py | 2 +- Lib/test/test_collections.py | 4 ++-- Misc/NEWS.d/next/Library/2018-01-11-00-33-42.bpo-32467.YVEOv6.rst | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-01-11-00-33-42.bpo-32467.YVEOv6.rst diff --git a/Doc/library/collections.abc.rst b/Doc/library/collections.abc.rst index 6015453..2a3fb14 100644 --- a/Doc/library/collections.abc.rst +++ b/Doc/library/collections.abc.rst @@ -87,7 +87,8 @@ ABC Inherits from Abstract Methods Mixin :class:`Set` ``__iter__`` :class:`KeysView` :class:`MappingView`, ``__contains__``, :class:`Set` ``__iter__`` -:class:`ValuesView` :class:`MappingView` ``__contains__``, ``__iter__`` +:class:`ValuesView` :class:`MappingView`, ``__contains__``, ``__iter__`` + :class:`Collection` :class:`Awaitable` ``__await__`` :class:`Coroutine` :class:`Awaitable` ``send``, ``throw`` ``close`` :class:`AsyncIterable` ``__aiter__`` diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index a5c7bfc..dbe30df 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -746,7 +746,7 @@ class ItemsView(MappingView, Set): ItemsView.register(dict_items) -class ValuesView(MappingView): +class ValuesView(MappingView, Collection): __slots__ = () diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index cb66235..a55239e 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -843,13 +843,13 @@ class TestOneTrickPonyABCs(ABCTestCase): self.assertFalse(issubclass(type(x), Collection), repr(type(x))) # Check some non-collection iterables non_col_iterables = [_test_gen(), iter(b''), iter(bytearray()), - (x for x in []), dict().values()] + (x for x in [])] for x in non_col_iterables: self.assertNotIsInstance(x, Collection) self.assertFalse(issubclass(type(x), Collection), repr(type(x))) # Check some collections samples = [set(), frozenset(), dict(), bytes(), str(), tuple(), - list(), dict().keys(), dict().items()] + list(), dict().keys(), dict().items(), dict().values()] for x in samples: self.assertIsInstance(x, Collection) self.assertTrue(issubclass(type(x), Collection), repr(type(x))) diff --git a/Misc/NEWS.d/next/Library/2018-01-11-00-33-42.bpo-32467.YVEOv6.rst b/Misc/NEWS.d/next/Library/2018-01-11-00-33-42.bpo-32467.YVEOv6.rst new file mode 100644 index 0000000..58bf066 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-01-11-00-33-42.bpo-32467.YVEOv6.rst @@ -0,0 +1 @@ +collections.abc.ValuesView now inherits from collections.abc.Collection. -- cgit v0.12