bpo-30143: 2to3 now generates a code that uses abstract collection cl… · python/cpython@0a2abdf · GitHub
Skip to content

Commit 0a2abdf

Browse files
bpo-30143: 2to3 now generates a code that uses abstract collection classes (#1262)
from collections.abc rather than collections.
1 parent a7368ac commit 0a2abdf

4 files changed

Lines changed: 18 additions & 16 deletions

File tree

Doc/library/2to3.rst

Lines changed: 6 additions & 6 deletions

Lib/lib2to3/fixes/fix_operator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
operator.isCallable(obj) -> hasattr(obj, '__call__')
44
operator.sequenceIncludes(obj) -> operator.contains(obj)
5-
operator.isSequenceType(obj) -> isinstance(obj, collections.Sequence)
6-
operator.isMappingType(obj) -> isinstance(obj, collections.Mapping)
5+
operator.isSequenceType(obj) -> isinstance(obj, collections.abc.Sequence)
6+
operator.isMappingType(obj) -> isinstance(obj, collections.abc.Mapping)
77
operator.isNumberType(obj) -> isinstance(obj, numbers.Number)
88
operator.repeat(obj, n) -> operator.mul(obj, n)
99
operator.irepeat(obj, n) -> operator.imul(obj, n)
@@ -63,13 +63,13 @@ def _repeat(self, node, results):
6363
def _irepeat(self, node, results):
6464
return self._handle_rename(node, results, "imul")
6565

66-
@invocation("isinstance(%s, collections.Sequence)")
66+
@invocation("isinstance(%s, collections.abc.Sequence)")
6767
def _isSequenceType(self, node, results):
68-
return self._handle_type2abc(node, results, "collections", "Sequence")
68+
return self._handle_type2abc(node, results, "collections.abc", "Sequence")
6969

70-
@invocation("isinstance(%s, collections.Mapping)")
70+
@invocation("isinstance(%s, collections.abc.Mapping)")
7171
def _isMappingType(self, node, results):
72-
return self._handle_type2abc(node, results, "collections", "Mapping")
72+
return self._handle_type2abc(node, results, "collections.abc", "Mapping")
7373

7474
@invocation("isinstance(%s, numbers.Number)")
7575
def _isNumberType(self, node, results):

Lib/lib2to3/tests/test_fixers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,12 +4427,12 @@ def test_operator_sequenceIncludes(self):
44274427

44284428
def test_operator_isSequenceType(self):
44294429
b = "operator.isSequenceType(x)"
4430-
a = "import collections\nisinstance(x, collections.Sequence)"
4430+
a = "import collections.abc\nisinstance(x, collections.abc.Sequence)"
44314431
self.check(b, a)
44324432

44334433
def test_operator_isMappingType(self):
44344434
b = "operator.isMappingType(x)"
4435-
a = "import collections\nisinstance(x, collections.Mapping)"
4435+
a = "import collections.abc\nisinstance(x, collections.abc.Mapping)"
44364436
self.check(b, a)
44374437

44384438
def test_operator_isNumberType(self):
@@ -4478,12 +4478,12 @@ def test_bare_sequenceIncludes(self):
44784478

44794479
def test_bare_operator_isSequenceType(self):
44804480
s = "isSequenceType(z)"
4481-
t = "You should use 'isinstance(z, collections.Sequence)' here."
4481+
t = "You should use 'isinstance(z, collections.abc.Sequence)' here."
44824482
self.warns_unchanged(s, t)
44834483

44844484
def test_bare_operator_isMappingType(self):
44854485
s = "isMappingType(x)"
4486-
t = "You should use 'isinstance(x, collections.Mapping)' here."
4486+
t = "You should use 'isinstance(x, collections.abc.Mapping)' here."
44874487
self.warns_unchanged(s, t)
44884488

44894489
def test_bare_operator_isNumberType(self):
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)