Skip to content

ABCs should be imported from collections.abc #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion graphql/execution/executor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import collections

try:
from collections.abc import Iterable
except ImportError: # Python < 3.3
from collections import Iterable
import functools
import logging
import sys
Expand Down Expand Up @@ -580,7 +585,7 @@ def complete_list_value(
"""
Complete a list value by completing each item in the list with the inner type
"""
assert isinstance(result, collections.Iterable), (
assert isinstance(result, Iterable), (
"User Error: expected iterable, but did not find one " + "for field {}.{}."
).format(info.parent_type, info.field_name)

Expand Down
9 changes: 5 additions & 4 deletions graphql/execution/values.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import collections
try:
from collections.abc import Iterable
except ImportError: # Python <3.3
from collections import Iterable
import json

from six import string_types
Expand Down Expand Up @@ -159,9 +162,7 @@ def coerce_value(type, value):

if isinstance(type, GraphQLList):
item_type = type.of_type
if not isinstance(value, string_types) and isinstance(
value, collections.Iterable
):
if not isinstance(value, string_types) and isinstance(value, Iterable):
return [coerce_value(item_type, item) for item in value]
else:
return [coerce_value(item_type, value)]
Expand Down
17 changes: 11 additions & 6 deletions graphql/type/definition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import collections

try:
from collections.abc import Hashable, Mapping
except ImportError: # Python < 3.3
from collections import Hashable, Mapping
import copy

from ..language import ast
Expand Down Expand Up @@ -234,7 +239,7 @@ def define_field_map(
if callable(field_map):
field_map = field_map()

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

if field_args:
assert isinstance(
field_args, collections.Mapping
field_args, Mapping
), "{}.{} args must be a mapping (dict / OrderedDict) with argument names as keys.".format(
type, field_name
)
Expand Down Expand Up @@ -520,15 +525,15 @@ def serialize(self, value):
if isinstance(value, PyEnum):
# We handle PyEnum values
value = value.value
if isinstance(value, collections.Hashable):
if isinstance(value, Hashable):
enum_value = self._value_lookup.get(value)
if enum_value:
return enum_value.name

return None

def parse_value(self, value):
if isinstance(value, collections.Hashable):
if isinstance(value, Hashable):
enum_value = self._name_lookup.get(value)

if enum_value:
Expand All @@ -555,7 +560,7 @@ def _name_lookup(self):

def define_enum_values(type, value_map):
assert (
isinstance(value_map, collections.Mapping) and len(value_map) > 0
isinstance(value_map, Mapping) and len(value_map) > 0
), "{} values must be a mapping (dict / OrderedDict) with value names as keys.".format(
type
)
Expand Down Expand Up @@ -661,7 +666,7 @@ def _define_field_map(self):
else:
fields = self._fields

assert isinstance(fields, collections.Mapping) and len(fields) > 0, (
assert isinstance(fields, Mapping) and len(fields) > 0, (
"{} fields must be a mapping (dict / OrderedDict) with field names as keys or a "
"function which returns such a mapping."
).format(self)
Expand Down
11 changes: 6 additions & 5 deletions graphql/type/directives.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import collections
try:
from collections.abc import Iterable, Mapping
except ImportError: # Python < 3.3
from collections import Iterable, Mapping

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

self.name = name
self.description = description
self.locations = locations

if args:
assert isinstance(
args, collections.Mapping
args, Mapping
), "{} args must be a dict with argument names as keys.".format(name)
for arg_name, _arg in args.items():
assert_valid_name(arg_name)
Expand Down
5 changes: 4 additions & 1 deletion graphql/type/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from collections import Iterable
try:
from collections.abc import Iterable
except ImportError: # Python < 3.3
from collections import Iterable

from .definition import GraphQLObjectType
from .directives import GraphQLDirective, specified_directives
Expand Down
2 changes: 1 addition & 1 deletion graphql/type/typemap.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import OrderedDict, Sequence, defaultdict
from collections import OrderedDict, defaultdict
from functools import reduce

from ..utils.type_comparators import is_equal_type, is_type_sub_type_of
Expand Down
11 changes: 6 additions & 5 deletions graphql/utils/is_valid_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
Implementation of isValidJSValue from graphql.s
"""

import collections
try:
from collections.abc import Iterable, Mapping
except ImportError: # Python < 3.3
from collections import Iterable, Mapping
import json

from six import string_types
Expand Down Expand Up @@ -37,9 +40,7 @@ def is_valid_value(value, type):

if isinstance(type, GraphQLList):
item_type = type.of_type
if not isinstance(value, string_types) and isinstance(
value, collections.Iterable
):
if not isinstance(value, string_types) and isinstance(value, Iterable):
errors = []
for i, item in enumerate(value):
item_errors = is_valid_value(item, item_type)
Expand All @@ -52,7 +53,7 @@ def is_valid_value(value, type):
return is_valid_value(value, item_type)

if isinstance(type, GraphQLInputObjectType):
if not isinstance(value, collections.Mapping):
if not isinstance(value, Mapping):
return [u'Expected "{}", found not an object.'.format(type)]

fields = type.fields
Expand Down