From c3bda9eeb1d802cd95b3120925d3786a4f060025 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 1 Feb 2021 10:31:17 +0000 Subject: [PATCH] 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 Change-Id: Ib07d778a01275d7c985e059156e95abc112e81c8 --- yaql/language/utils.py | 32 ++++++++++++++++---------------- yaql/language/yaqltypes.py | 4 ++-- yaql/standard_library/queries.py | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/yaql/language/utils.py b/yaql/language/utils.py index 97ad8d9..8240baa 100644 --- a/yaql/language/utils.py +++ b/yaql/language/utils.py @@ -32,35 +32,35 @@ NO_VALUE = create_marker('') 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 diff --git a/yaql/language/yaqltypes.py b/yaql/language/yaqltypes.py index 14a7301..d3c8693 100644 --- a/yaql/language/yaqltypes.py +++ b/yaql/language/yaqltypes.py @@ -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 [])) diff --git a/yaql/standard_library/queries.py b/yaql/standard_library/queries.py index 103529d..5cc8163 100644 --- a/yaql/standard_library/queries.py +++ b/yaql/standard_library/queries.py @@ -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]