Switch to collections.abc.*

The abstract base classes previously defined in 'collections' were moved
to 'collections.abc' in 3.3. The aliases will be removed in 3.10.
Preempt this change now with a simple find-replace:

  $ ag -l 'collections.($TYPES)' | \
      xargs sed -i 's/\(collections\)\.\($TYPES\)/\1.abc.\2/g'

Where $TYPES is the list of moved ABCs from [1].

[1] https://docs.python.org/3/library/collections.abc.html

Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Change-Id: Ib07d778a01275d7c985e059156e95abc112e81c8
This commit is contained in:
Stephen Finucane 2021-02-01 10:31:17 +00:00
parent 4670f0949c
commit c3bda9eeb1
3 changed files with 19 additions and 19 deletions

View File

@ -32,35 +32,35 @@ NO_VALUE = create_marker('<NoValue>')
def is_iterator(obj):
return isinstance(obj, collections.Iterator)
return isinstance(obj, collections.abc.Iterator)
def is_iterable(obj):
return (
isinstance(obj, collections.Iterable) and
isinstance(obj, collections.abc.Iterable) and
not isinstance(obj, (str, MappingType))
)
def is_sequence(obj):
return isinstance(obj, collections.Sequence) and not isinstance(
return isinstance(obj, collections.abc.Sequence) and not isinstance(
obj, str)
def is_mutable(obj):
return isinstance(obj, (collections.MutableSequence,
collections.MutableSet,
collections.MutableMapping))
return isinstance(obj, (collections.abc.MutableSequence,
collections.abc.MutableSet,
collections.abc.MutableMapping))
SequenceType = collections.Sequence
MutableSequenceType = collections.MutableSequence
SetType = collections.Set
MutableSetType = collections.MutableSet
MappingType = collections.Mapping
MutableMappingType = collections.MutableMapping
IterableType = collections.Iterable
IteratorType = collections.Iterator
SequenceType = collections.abc.Sequence
MutableSequenceType = collections.abc.MutableSequence
SetType = collections.abc.Set
MutableSetType = collections.abc.MutableSet
MappingType = collections.abc.Mapping
MutableMappingType = collections.abc.MutableMapping
IterableType = collections.abc.Iterable
IteratorType = collections.abc.Iterator
QueueType = collections.deque
@ -85,7 +85,7 @@ def convert_input_data(obj, rec=None):
def convert_output_data(obj, limit_func, engine, rec=None):
if rec is None:
rec = convert_output_data
if isinstance(obj, collections.Mapping):
if isinstance(obj, collections.abc.Mapping):
result = {}
for key, value in limit_func(obj.items()):
result[rec(key, limit_func, engine, rec)] = rec(
@ -119,7 +119,7 @@ class MappingRule(object):
self.destination = destination
class FrozenDict(collections.Mapping):
class FrozenDict(collections.abc.Mapping):
def __init__(self, *args, **kwargs):
self._d = dict(*args, **kwargs)
self._hash = None

View File

@ -185,7 +185,7 @@ class Iterable(PythonType):
def __init__(self, validators=None, nullable=False):
super(Iterable, self).__init__(
collections.Iterable, nullable,
collections.abc.Iterable, nullable,
[lambda t: not isinstance(t, (str, utils.MappingType))] + (
validators or []))
@ -217,7 +217,7 @@ class Sequence(PythonType):
def __init__(self, validators=None, nullable=False):
super(Sequence, self).__init__(
collections.Sequence, nullable, [
collections.abc.Sequence, nullable, [
lambda t: not isinstance(t, (str, dict))] + (
validators or []))

View File

@ -883,7 +883,7 @@ class GroupAggregator(object):
else:
if not (
len(value_list) == 2 and
isinstance(result, collections.Sequence) and
isinstance(result, collections.abc.Sequence) and
not isinstance(result, str) and
len(result) == 2 and
result[0] == value_list[0]