From 1878cec0d1d320cc20590530c6043498bd8f20c1 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 28 Jan 2018 23:46:37 -0800 Subject: [PATCH 1/2] Deprecate exposing collections.abc in collections --- Doc/library/collections.rst | 4 ++-- Doc/whatsnew/3.7.rst | 5 +++++ Lib/collections/__init__.py | 10 +++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 18aaba65b252c37..772ff60fe9839ac 100644 --- a/Doc/library/collections.rst +++ b/Doc/library/collections.rst @@ -35,8 +35,8 @@ Python's general purpose built-in containers, :class:`dict`, :class:`list`, .. versionchanged:: 3.3 Moved :ref:`collections-abstract-base-classes` to the :mod:`collections.abc` module. - For backwards compatibility, they continue to be visible in this module - as well. + For backwards compatibility, they continue to be visible in this module through + Python 3.7. Subsequently, they will be removed entirely. :class:`ChainMap` objects diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 9979e69239907a2..a2a0e37f81300a5 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -874,6 +874,11 @@ Other CPython Implementation Changes Deprecated ========== +* In Python 3.8, the abstract base classes in :mod:`collections.abc` will no + longer be exposed in the regular :mod:`collections` module. This will help + create a clearer distinction between the concrete classes and the abstract + base classes. + * Yield expressions (both ``yield`` and ``yield from`` clauses) are now deprecated in comprehensions and generator expressions (aside from the iterable expression in the leftmost :keyword:`for` clause). This ensures that comprehensions diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 21d91fd61d607c6..8aeee359cd623e1 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -18,10 +18,14 @@ 'UserString', 'Counter', 'OrderedDict', 'ChainMap'] # For backwards compatibility, continue to make the collections ABCs -# available through the collections module. -from _collections_abc import * +# through Python 3.6 available through the collections module. +# Note, no new collections ABCs were added in Python 3.7 import _collections_abc -__all__ += _collections_abc.__all__ +from _collections_abc import (AsyncGenerator, AsyncIterable, AsyncIterator, + Awaitable, ByteString, Callable, Collection, Container, Coroutine, + Generator, Hashable, ItemsView, Iterable, Iterator, KeysView, Mapping, + MappingView, MutableMapping, MutableSequence, MutableSet, Reversible, + Sequence, Set, Sized, ValuesView) from operator import itemgetter as _itemgetter, eq as _eq from keyword import iskeyword as _iskeyword From b1e806d79400f2a2935928efb08003a7d272a2ed Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Sun, 28 Jan 2018 23:49:11 -0800 Subject: [PATCH 2/2] Add news blurb --- .../next/Library/2018-01-28-23-48-45.bpo-25988.I9uBct.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2018-01-28-23-48-45.bpo-25988.I9uBct.rst diff --git a/Misc/NEWS.d/next/Library/2018-01-28-23-48-45.bpo-25988.I9uBct.rst b/Misc/NEWS.d/next/Library/2018-01-28-23-48-45.bpo-25988.I9uBct.rst new file mode 100644 index 000000000000000..df350779ea4a16a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-01-28-23-48-45.bpo-25988.I9uBct.rst @@ -0,0 +1,2 @@ +Deprecate exposing the contents of collections.abc in the regular +collections module.