Python 3.10.0, released on October 4, 2021, removes the deprecated abstract-base-class aliases from the collections module. Code importing Mapping, MutableMapping or Sequence from collections needs to import those names from collections.abc instead. The removal does not mean that collections itself has gone away: container tools including Counter, defaultdict, deque and namedtuple remain there. [S1][S2][S3][S4]
The distinction matters because an abstract base class describes an interface, rather than one concrete way to store data. Python’s documentation uses these classes to test whether an object supports a particular interface, such as a mapping. Classes can inherit from an abstract base class or register as virtual subclasses. Replacing a Mapping check with a dict check is not an equivalent repair: it asks whether the object belongs to the dict type hierarchy, rather than the broader mapping interface. Moving the import preserves the intended category of the check. [S3]
For a mixed import, the change is selective. A statement such as from collections import Counter, Mapping should be split so that Counter still comes from collections and Mapping comes from collections.abc. The release’s container documentation continues to describe Counter as a dictionary subclass for counting hashable objects. A blanket replacement of collections with collections.abc would therefore send a supported container import to the wrong module. Check the imported names, not just the module name. [S2][S3][S4]
For teams maintaining business scripts, our recommendation is to inspect imports in both their own code and the dependencies those scripts load before switching a scheduled job to Python 3.10. If a dependency still requests a removed alias, changing only the application’s imports does not fix that request. Test the job with its intended dependency versions under the new interpreter; editing an import line is not evidence that the whole job is compatible. [S2][S3]
There is a separate trap in checking for iterable objects. The Python 3.10 documentation says isinstance(obj, Iterable) recognizes registered classes and classes with an __iter__ method, but does not detect objects that iterate through __getitem__. It identifies calling iter(obj) as the reliable way to determine whether an object is iterable. The supported import path does not make Iterable a test for every object that can be iterated. [S3]
Source documents
- Python 3.10.0 release pagehttps://www.python.org/downloads/release/python-3100/
- What’s New In Python 3.10 — v3.10.0 sourcehttps://raw.githubusercontent.com/python/cpython/b494f5935c92951e75597bfe1c8b1f3112fec270/Doc/whatsnew/3.10.rst
- collections.abc — v3.10.0 documentationhttps://raw.githubusercontent.com/python/cpython/b494f5935c92951e75597bfe1c8b1f3112fec270/Doc/library/collections.abc.rst
- collections — v3.10.0 documentationhttps://raw.githubusercontent.com/python/cpython/b494f5935c92951e75597bfe1c8b1f3112fec270/Doc/library/collections.rst
