Skip to content

Commit cd01f76

Browse files
committed
Fix Python 3.7 deprecation warnings
Importing ABCs directly from the `collections` module is deprecated in Python 3.7.
1 parent 9202021 commit cd01f76

File tree

7 files changed

+20
-17
lines changed

7 files changed

+20
-17
lines changed

graphql/execution/executor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import collections
2+
import collections.abc
23
import functools
34
import logging
45
import sys
@@ -580,7 +581,7 @@ def complete_list_value(
580581
"""
581582
Complete a list value by completing each item in the list with the inner type
582583
"""
583-
assert isinstance(result, collections.Iterable), (
584+
assert isinstance(result, collections.abc.Iterable), (
584585
"User Error: expected iterable, but did not find one " + "for field {}.{}."
585586
).format(info.parent_type, info.field_name)
586587

graphql/execution/values.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import collections
1+
import collections.abc
22
import json
33

44
from six import string_types
@@ -160,7 +160,7 @@ def coerce_value(type, value):
160160
if isinstance(type, GraphQLList):
161161
item_type = type.of_type
162162
if not isinstance(value, string_types) and isinstance(
163-
value, collections.Iterable
163+
value, collections.abc.Iterable
164164
):
165165
return [coerce_value(item_type, item) for item in value]
166166
else:

graphql/type/definition.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import collections
2+
import collections.abc
23
import copy
34

45
from ..language import ast
@@ -234,7 +235,7 @@ def define_field_map(
234235
if callable(field_map):
235236
field_map = field_map()
236237

237-
assert isinstance(field_map, collections.Mapping) and len(field_map) > 0, (
238+
assert isinstance(field_map, collections.abc.Mapping) and len(field_map) > 0, (
238239
"{} fields must be a mapping (dict / OrderedDict) with field names as keys or a "
239240
"function which returns such a mapping."
240241
).format(type)
@@ -248,7 +249,7 @@ def define_field_map(
248249

249250
if field_args:
250251
assert isinstance(
251-
field_args, collections.Mapping
252+
field_args, collections.abc.Mapping
252253
), "{}.{} args must be a mapping (dict / OrderedDict) with argument names as keys.".format(
253254
type, field_name
254255
)
@@ -520,15 +521,15 @@ def serialize(self, value):
520521
if isinstance(value, PyEnum):
521522
# We handle PyEnum values
522523
value = value.value
523-
if isinstance(value, collections.Hashable):
524+
if isinstance(value, collections.abc.Hashable):
524525
enum_value = self._value_lookup.get(value)
525526
if enum_value:
526527
return enum_value.name
527528

528529
return None
529530

530531
def parse_value(self, value):
531-
if isinstance(value, collections.Hashable):
532+
if isinstance(value, collections.abc.Hashable):
532533
enum_value = self._name_lookup.get(value)
533534

534535
if enum_value:
@@ -555,7 +556,7 @@ def _name_lookup(self):
555556

556557
def define_enum_values(type, value_map):
557558
assert (
558-
isinstance(value_map, collections.Mapping) and len(value_map) > 0
559+
isinstance(value_map, collections.abc.Mapping) and len(value_map) > 0
559560
), "{} values must be a mapping (dict / OrderedDict) with value names as keys.".format(
560561
type
561562
)
@@ -661,7 +662,7 @@ def _define_field_map(self):
661662
else:
662663
fields = self._fields
663664

664-
assert isinstance(fields, collections.Mapping) and len(fields) > 0, (
665+
assert isinstance(fields, collections.abc.Mapping) and len(fields) > 0, (
665666
"{} fields must be a mapping (dict / OrderedDict) with field names as keys or a "
666667
"function which returns such a mapping."
667668
).format(self)

graphql/type/directives.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import collections
1+
import collections.abc
22

33
from ..pyutils.ordereddict import OrderedDict
44
from ..utils.assert_valid_name import assert_valid_name
@@ -43,7 +43,7 @@ def __init__(self, name, description=None, args=None, locations=None):
4343
assert name, "Directive must be named."
4444
assert_valid_name(name)
4545
assert isinstance(
46-
locations, collections.Iterable
46+
locations, collections.abc.Iterable
4747
), "Must provide locations for directive."
4848

4949
self.name = name
@@ -52,7 +52,7 @@ def __init__(self, name, description=None, args=None, locations=None):
5252

5353
if args:
5454
assert isinstance(
55-
args, collections.Mapping
55+
args, collections.abc.Mapping
5656
), "{} args must be a dict with argument names as keys.".format(name)
5757
for arg_name, _arg in args.items():
5858
assert_valid_name(arg_name)

graphql/type/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import Iterable
1+
from collections.abc import Iterable
22

33
from .definition import GraphQLObjectType
44
from .directives import GraphQLDirective, specified_directives

graphql/type/typemap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from collections import OrderedDict, Sequence, defaultdict
1+
from collections import OrderedDict, defaultdict
2+
from collections.abc import Sequence
23
from functools import reduce
34

45
from ..utils.type_comparators import is_equal_type, is_type_sub_type_of

graphql/utils/is_valid_value.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Implementation of isValidJSValue from graphql.s
33
"""
44

5-
import collections
5+
import collections.abc
66
import json
77

88
from six import string_types
@@ -38,7 +38,7 @@ def is_valid_value(value, type):
3838
if isinstance(type, GraphQLList):
3939
item_type = type.of_type
4040
if not isinstance(value, string_types) and isinstance(
41-
value, collections.Iterable
41+
value, collections.abc.Iterable
4242
):
4343
errors = []
4444
for i, item in enumerate(value):
@@ -52,7 +52,7 @@ def is_valid_value(value, type):
5252
return is_valid_value(value, item_type)
5353

5454
if isinstance(type, GraphQLInputObjectType):
55-
if not isinstance(value, collections.Mapping):
55+
if not isinstance(value, collections.abc.Mapping):
5656
return [u'Expected "{}", found not an object.'.format(type)]
5757

5858
fields = type.fields

0 commit comments

Comments
 (0)