Skip to content

Commit cdb299d

Browse files
authored
Merge pull request #226 from Cito/master
ABCs should be imported from collections.abc
2 parents 9202021 + b3f40b2 commit cdb299d

File tree

7 files changed

+39
-23
lines changed

7 files changed

+39
-23
lines changed

graphql/execution/executor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import collections
2+
3+
try:
4+
from collections.abc import Iterable
5+
except ImportError: # Python < 3.3
6+
from collections import Iterable
27
import functools
38
import logging
49
import sys
@@ -580,7 +585,7 @@ def complete_list_value(
580585
"""
581586
Complete a list value by completing each item in the list with the inner type
582587
"""
583-
assert isinstance(result, collections.Iterable), (
588+
assert isinstance(result, Iterable), (
584589
"User Error: expected iterable, but did not find one " + "for field {}.{}."
585590
).format(info.parent_type, info.field_name)
586591

graphql/execution/values.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import collections
1+
try:
2+
from collections.abc import Iterable
3+
except ImportError: # Python <3.3
4+
from collections import Iterable
25
import json
36

47
from six import string_types
@@ -159,9 +162,7 @@ def coerce_value(type, value):
159162

160163
if isinstance(type, GraphQLList):
161164
item_type = type.of_type
162-
if not isinstance(value, string_types) and isinstance(
163-
value, collections.Iterable
164-
):
165+
if not isinstance(value, string_types) and isinstance(value, Iterable):
165166
return [coerce_value(item_type, item) for item in value]
166167
else:
167168
return [coerce_value(item_type, value)]

graphql/type/definition.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import collections
2+
3+
try:
4+
from collections.abc import Hashable, Mapping
5+
except ImportError: # Python < 3.3
6+
from collections import Hashable, Mapping
27
import copy
38

49
from ..language import ast
@@ -234,7 +239,7 @@ def define_field_map(
234239
if callable(field_map):
235240
field_map = field_map()
236241

237-
assert isinstance(field_map, collections.Mapping) and len(field_map) > 0, (
242+
assert isinstance(field_map, Mapping) and len(field_map) > 0, (
238243
"{} fields must be a mapping (dict / OrderedDict) with field names as keys or a "
239244
"function which returns such a mapping."
240245
).format(type)
@@ -248,7 +253,7 @@ def define_field_map(
248253

249254
if field_args:
250255
assert isinstance(
251-
field_args, collections.Mapping
256+
field_args, Mapping
252257
), "{}.{} args must be a mapping (dict / OrderedDict) with argument names as keys.".format(
253258
type, field_name
254259
)
@@ -520,15 +525,15 @@ def serialize(self, value):
520525
if isinstance(value, PyEnum):
521526
# We handle PyEnum values
522527
value = value.value
523-
if isinstance(value, collections.Hashable):
528+
if isinstance(value, Hashable):
524529
enum_value = self._value_lookup.get(value)
525530
if enum_value:
526531
return enum_value.name
527532

528533
return None
529534

530535
def parse_value(self, value):
531-
if isinstance(value, collections.Hashable):
536+
if isinstance(value, Hashable):
532537
enum_value = self._name_lookup.get(value)
533538

534539
if enum_value:
@@ -555,7 +560,7 @@ def _name_lookup(self):
555560

556561
def define_enum_values(type, value_map):
557562
assert (
558-
isinstance(value_map, collections.Mapping) and len(value_map) > 0
563+
isinstance(value_map, Mapping) and len(value_map) > 0
559564
), "{} values must be a mapping (dict / OrderedDict) with value names as keys.".format(
560565
type
561566
)
@@ -661,7 +666,7 @@ def _define_field_map(self):
661666
else:
662667
fields = self._fields
663668

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

graphql/type/directives.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import collections
1+
try:
2+
from collections.abc import Iterable, Mapping
3+
except ImportError: # Python < 3.3
4+
from collections import Iterable, Mapping
25

36
from ..pyutils.ordereddict import OrderedDict
47
from ..utils.assert_valid_name import assert_valid_name
@@ -42,17 +45,15 @@ class GraphQLDirective(object):
4245
def __init__(self, name, description=None, args=None, locations=None):
4346
assert name, "Directive must be named."
4447
assert_valid_name(name)
45-
assert isinstance(
46-
locations, collections.Iterable
47-
), "Must provide locations for directive."
48+
assert isinstance(locations, Iterable), "Must provide locations for directive."
4849

4950
self.name = name
5051
self.description = description
5152
self.locations = locations
5253

5354
if args:
5455
assert isinstance(
55-
args, collections.Mapping
56+
args, Mapping
5657
), "{} args must be a dict with argument names as keys.".format(name)
5758
for arg_name, _arg in args.items():
5859
assert_valid_name(arg_name)

graphql/type/schema.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from collections import Iterable
1+
try:
2+
from collections.abc import Iterable
3+
except ImportError: # Python < 3.3
4+
from collections import Iterable
25

36
from .definition import GraphQLObjectType
47
from .directives import GraphQLDirective, specified_directives

graphql/type/typemap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import OrderedDict, Sequence, defaultdict
1+
from collections import OrderedDict, defaultdict
22
from functools import reduce
33

44
from ..utils.type_comparators import is_equal_type, is_type_sub_type_of

graphql/utils/is_valid_value.py

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

5-
import collections
5+
try:
6+
from collections.abc import Iterable, Mapping
7+
except ImportError: # Python < 3.3
8+
from collections import Iterable, Mapping
69
import json
710

811
from six import string_types
@@ -37,9 +40,7 @@ def is_valid_value(value, type):
3740

3841
if isinstance(type, GraphQLList):
3942
item_type = type.of_type
40-
if not isinstance(value, string_types) and isinstance(
41-
value, collections.Iterable
42-
):
43+
if not isinstance(value, string_types) and isinstance(value, Iterable):
4344
errors = []
4445
for i, item in enumerate(value):
4546
item_errors = is_valid_value(item, item_type)
@@ -52,7 +53,7 @@ def is_valid_value(value, type):
5253
return is_valid_value(value, item_type)
5354

5455
if isinstance(type, GraphQLInputObjectType):
55-
if not isinstance(value, collections.Mapping):
56+
if not isinstance(value, Mapping):
5657
return [u'Expected "{}", found not an object.'.format(type)]
5758

5859
fields = type.fields

0 commit comments

Comments
 (0)