bpo-39674: Revert "bpo-25988: Do not expose abstract collection class… · python/cpython@af5ee3f

4 files changed

lines changed

Original file line numberDiff line numberDiff line change

@@ -33,7 +33,7 @@ Python's general purpose built-in containers, :class:`dict`, :class:`list`,

3333

:class:`UserString` wrapper around string objects for easier string subclassing

3434

===================== ====================================================================

3535
36-

.. deprecated-removed:: 3.3 3.9

36+

.. deprecated-removed:: 3.3 3.10

3737

Moved :ref:`collections-abstract-base-classes` to the :mod:`collections.abc` module.

3838

For backwards compatibility, they continue to be visible in this module through

3939

Python 3.8.

Original file line numberDiff line numberDiff line change

@@ -471,11 +471,6 @@ Removed

471471

since Python 3.2.

472472

(Contributed by Victor Stinner in :issue:`38916`.)

473473
474-

* The abstract base classes in :mod:`collections.abc` no longer are

475-

exposed in the regular :mod:`collections` module. This will help

476-

create a clearer distinction between the concrete classes and the abstract

477-

base classes.

478-
479474

* The undocumented ``sys.callstats()`` function has been removed. Since Python

480475

3.7, it was deprecated and always returned :const:`None`. It required a special

481476

build option ``CALL_PROFILE`` which was already removed in Python 3.7.

Original file line numberDiff line numberDiff line change

@@ -39,6 +39,21 @@

3939

pass

4040
4141
42+

def __getattr__(name):

43+

# For backwards compatibility, continue to make the collections ABCs

44+

# through Python 3.6 available through the collections module.

45+

# Note, no new collections ABCs were added in Python 3.7

46+

if name in _collections_abc.__all__:

47+

obj = getattr(_collections_abc, name)

48+

import warnings

49+

warnings.warn("Using or importing the ABCs from 'collections' instead "

50+

"of from 'collections.abc' is deprecated since Python 3.3, "

51+

"and in 3.10 it will stop working",

52+

DeprecationWarning, stacklevel=2)

53+

globals()[name] = obj

54+

return obj

55+

raise AttributeError(f'module {__name__!r} has no attribute {name!r}')

56+
4257

################################################################################

4358

### OrderedDict

4459

################################################################################

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,4 @@

1+

Revert "Do not expose abstract collection classes in the collections module"

2+

change (bpo-25988). Aliases to ABC like collections.Mapping are kept in

3+

Python 3.9 to ease transition from Python 2.7, but will be removed in Python

4+

3.10.