Skip to content

Commit 2e576f5

Browse files
bpo-30144: Import collections ABC from collections.abc rather than collections. (#1263)
1 parent 9eb5ca0 commit 2e576f5

22 files changed

Lines changed: 92 additions & 87 deletions

Doc/library/http.client.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ also send your request step by step, by using the four functions below.
372372
Section 3.3.1. How the data is encoded is dependent on the type of
373373
*message_body*. If *message_body* implements the :ref:`buffer interface
374374
<bufferobjects>` the encoding will result in a single chunk.
375-
If *message_body* is a :class:`collections.Iterable`, each iteration
375+
If *message_body* is a :class:`collections.abc.Iterable`, each iteration
376376
of *message_body* will result in a chunk. If *message_body* is a
377377
:term:`file object`, each call to ``.read()`` will result in a chunk.
378378
The method automatically signals the end of the chunk-encoded data

Doc/reference/datamodel.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ Basic customization
13751375
:meth:`__hash__` method of a class is ``None``, instances of the class will
13761376
raise an appropriate :exc:`TypeError` when a program attempts to retrieve
13771377
their hash value, and will also be correctly identified as unhashable when
1378-
checking ``isinstance(obj, collections.Hashable)``.
1378+
checking ``isinstance(obj, collections.abc.Hashable)``.
13791379

13801380
If a class that overrides :meth:`__eq__` needs to retain the implementation
13811381
of :meth:`__hash__` from a parent class, the interpreter must be told this
@@ -1385,7 +1385,7 @@ Basic customization
13851385
support, it should include ``__hash__ = None`` in the class definition.
13861386
A class which defines its own :meth:`__hash__` that explicitly raises
13871387
a :exc:`TypeError` would be incorrectly identified as hashable by
1388-
an ``isinstance(obj, collections.Hashable)`` call.
1388+
an ``isinstance(obj, collections.abc.Hashable)`` call.
13891389

13901390

13911391
.. note::
@@ -1981,7 +1981,7 @@ range of items. It is also recommended that mappings provide the methods
19811981
:meth:`keys`, :meth:`values`, :meth:`items`, :meth:`get`, :meth:`clear`,
19821982
:meth:`setdefault`, :meth:`pop`, :meth:`popitem`, :meth:`!copy`, and
19831983
:meth:`update` behaving similar to those for Python's standard dictionary
1984-
objects. The :mod:`collections` module provides a
1984+
objects. The :mod:`collections.abc` module provides a
19851985
:class:`~collections.abc.MutableMapping`
19861986
abstract base class to help create those methods from a base set of
19871987
:meth:`__getitem__`, :meth:`__setitem__`, :meth:`__delitem__`, and :meth:`keys`.

Lib/asyncio/base_events.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""
1515

1616
import collections
17+
import collections.abc
1718
import concurrent.futures
1819
import heapq
1920
import itertools
@@ -1001,7 +1002,7 @@ def create_server(self, protocol_factory, host=None, port=None,
10011002
if host == '':
10021003
hosts = [None]
10031004
elif (isinstance(host, str) or
1004-
not isinstance(host, collections.Iterable)):
1005+
not isinstance(host, collections.abc.Iterable)):
10051006
hosts = [host]
10061007
else:
10071008
hosts = host

Lib/cgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# =======
3333

3434
from io import StringIO, BytesIO, TextIOWrapper
35-
from collections import Mapping
35+
from collections.abc import Mapping
3636
import sys
3737
import os
3838
import urllib.parse

Lib/dbm/dumb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
import ast as _ast
2525
import io as _io
2626
import os as _os
27-
import collections
27+
import collections.abc
2828

2929
__all__ = ["error", "open"]
3030

3131
_BLOCKSIZE = 512
3232

3333
error = OSError
3434

35-
class _Database(collections.MutableMapping):
35+
class _Database(collections.abc.MutableMapping):
3636

3737
# The on-disk directory and data files can remain in mutually
3838
# inconsistent states for an arbitrarily long time (see comments

Lib/http/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
import io
7575
import re
7676
import socket
77-
import collections
77+
import collections.abc
7878
from urllib.parse import urlsplit
7979

8080
# HTTPMessage, parse_headers(), and the HTTP status code constants are
@@ -977,7 +977,7 @@ def send(self, data):
977977
try:
978978
self.sock.sendall(data)
979979
except TypeError:
980-
if isinstance(data, collections.Iterable):
980+
if isinstance(data, collections.abc.Iterable):
981981
for d in data:
982982
self.sock.sendall(d)
983983
else:

Lib/idlelib/pyparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import Mapping
1+
from collections.abc import Mapping
22
import re
33
import sys
44

Lib/lib2to3/fixes/fix_operator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
operator.irepeat(obj, n) -> operator.imul(obj, n)
1010
"""
1111

12-
import collections
12+
import collections.abc
1313

1414
# Local imports
1515
from lib2to3 import fixer_base
@@ -88,7 +88,7 @@ def _handle_type2abc(self, node, results, module, abc):
8888

8989
def _check_method(self, node, results):
9090
method = getattr(self, "_" + results["method"][0].value)
91-
if isinstance(method, collections.Callable):
91+
if isinstance(method, collections.abc.Callable):
9292
if "module" in results:
9393
return method
9494
else:

Lib/locale.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import encodings
1515
import encodings.aliases
1616
import re
17-
import collections
17+
import collections.abc
1818
from builtins import str as _builtin_str
1919
import functools
2020
import warnings
@@ -215,7 +215,7 @@ def format_string(f, val, grouping=False, monetary=False):
215215
percents = list(_percent_re.finditer(f))
216216
new_f = _percent_re.sub('%s', f)
217217

218-
if isinstance(val, collections.Mapping):
218+
if isinstance(val, collections.abc.Mapping):
219219
new_val = []
220220
for perc in percents:
221221
if perc.group()[-1]=='%':

Lib/logging/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
To use, simply 'import logging' and log away!
2424
"""
2525

26-
import sys, os, time, io, traceback, warnings, weakref, collections
26+
import sys, os, time, io, traceback, warnings, weakref, collections.abc
2727

2828
from string import Template
2929

@@ -273,8 +273,8 @@ def __init__(self, name, level, pathname, lineno,
273273
# to hasattr(args[0], '__getitem__'). However, the docs on string
274274
# formatting still seem to suggest a mapping object is required.
275275
# Thus, while not removing the isinstance check, it does now look
276-
# for collections.Mapping rather than, as before, dict.
277-
if (args and len(args) == 1 and isinstance(args[0], collections.Mapping)
276+
# for collections.abc.Mapping rather than, as before, dict.
277+
if (args and len(args) == 1 and isinstance(args[0], collections.abc.Mapping)
278278
and args[0]):
279279
args = args[0]
280280
self.args = args

0 commit comments

Comments
 (0)