Skip to content

Commit 2ea2cd2

Browse files
committed
PEP8+Flake+isort 😎
1 parent c81f6a7 commit 2ea2cd2

File tree

113 files changed

+601
-565
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+601
-565
lines changed

‎bin/autolinter

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
# Install the required scripts with
4+
# pip install autoflake autopep8 isort
5+
autoflake ./graphql/ ./tests/ -r --remove-unused-variables --in-place
6+
autopep8 ./tests/ ./graphql/ -r --in-place --experimental --aggressive --max-line-length 120
7+
isort -rc ./tests/ ./graphql/

‎graphql/core/execution/base.py

+9-15
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,10 @@
22
from ..error import GraphQLError
33
from ..language import ast
44
from ..pyutils.defer import DeferredException
5-
from ..type.definition import (
6-
GraphQLInterfaceType,
7-
GraphQLUnionType,
8-
)
9-
from ..type.directives import (
10-
GraphQLIncludeDirective,
11-
GraphQLSkipDirective,
12-
)
13-
from ..type.introspection import (
14-
SchemaMetaFieldDef,
15-
TypeMetaFieldDef,
16-
TypeNameMetaFieldDef,
17-
)
5+
from ..type.definition import GraphQLInterfaceType, GraphQLUnionType
6+
from ..type.directives import GraphQLIncludeDirective, GraphQLSkipDirective
7+
from ..type.introspection import (SchemaMetaFieldDef, TypeMetaFieldDef,
8+
TypeNameMetaFieldDef)
189
from ..utils.type_from_ast import type_from_ast
1910
from .values import get_argument_values, get_variable_values
2011

@@ -97,7 +88,7 @@ def __init__(self, data=None, errors=None, invalid=False):
9788
errors = [
9889
error.value if isinstance(error, DeferredException) else error
9990
for error in errors
100-
]
91+
]
10192

10293
self.errors = errors
10394

@@ -170,7 +161,9 @@ def collect_fields(ctx, runtime_type, selection_set, fields, prev_fragment_names
170161
fields[name].append(selection)
171162

172163
elif isinstance(selection, ast.InlineFragment):
173-
if not should_include_node(ctx, directives) or not does_fragment_condition_match(ctx, selection, runtime_type):
164+
if not should_include_node(
165+
ctx, directives) or not does_fragment_condition_match(
166+
ctx, selection, runtime_type):
174167
continue
175168

176169
collect_fields(ctx, runtime_type, selection.selection_set, fields, prev_fragment_names)
@@ -255,6 +248,7 @@ def get_field_entry_key(node):
255248

256249

257250
class ResolveInfo(object):
251+
258252
def __init__(self, field_name, field_asts, return_type, parent_type, context):
259253
self.field_name = field_name
260254
self.field_asts = field_asts

‎graphql/core/execution/executor.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
from ..language.parser import parse
77
from ..language.source import Source
88
from ..pyutils.default_ordered_dict import DefaultOrderedDict
9-
from ..pyutils.defer import Deferred, DeferredDict, DeferredList, defer, succeed
10-
from ..type import GraphQLEnumType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, \
11-
GraphQLScalarType, GraphQLUnionType
9+
from ..pyutils.defer import (Deferred, DeferredDict, DeferredList, defer,
10+
succeed)
11+
from ..type import (GraphQLEnumType, GraphQLInterfaceType, GraphQLList,
12+
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
13+
GraphQLUnionType)
1214
from ..validation import validate
13-
from .base import ExecutionContext, ExecutionResult, ResolveInfo, Undefined, collect_fields, default_resolve_fn, \
14-
get_field_def, get_operation_root_type
15+
from .base import (ExecutionContext, ExecutionResult, ResolveInfo, Undefined,
16+
collect_fields, default_resolve_fn, get_field_def,
17+
get_operation_root_type)
1518

1619

1720
class Executor(object):
21+
1822
def __init__(self, execution_middlewares=None, default_resolver=default_resolve_fn, map_type=dict):
1923
assert issubclass(map_type, collections.MutableMapping)
2024

‎graphql/core/execution/middlewares/asyncio.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def handle_future_result(future):
1717

1818

1919
class AsyncioExecutionMiddleware(object):
20+
2021
@staticmethod
2122
def run_resolve_fn(resolver, original_resolver):
2223
result = resolver()

‎graphql/core/execution/middlewares/gevent.py

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def resolve_something(context, _*):
3030

3131

3232
class GeventExecutionMiddleware(object):
33+
3334
@staticmethod
3435
def run_resolve_fn(resolver, original_resolver):
3536
if resolver_has_tag(original_resolver, 'run_in_greenlet'):

‎graphql/core/execution/middlewares/sync.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
class SynchronousExecutionMiddleware(object):
6+
67
@staticmethod
78
def run_resolve_fn(resolver, original_resolver):
89
result = resolver()

‎graphql/core/execution/values.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import collections
22
import json
3+
34
from six import string_types
5+
46
from ..error import GraphQLError
57
from ..language.printer import print_ast
6-
from ..type import (
7-
GraphQLEnumType,
8-
GraphQLInputObjectType,
9-
GraphQLList,
10-
GraphQLNonNull,
11-
GraphQLScalarType,
12-
is_input_type
13-
)
8+
from ..type import (GraphQLEnumType, GraphQLInputObjectType, GraphQLList,
9+
GraphQLNonNull, GraphQLScalarType, is_input_type)
1410
from ..utils.is_valid_value import is_valid_value
1511
from ..utils.type_from_ast import type_from_ast
1612
from ..utils.value_from_ast import value_from_ast

‎graphql/core/language/error.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
class LanguageError(GraphQLError):
8+
89
def __init__(self, source, position, description):
910
location = get_location(source, position)
1011
super(LanguageError, self).__init__(

‎graphql/core/language/lexer.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import json
2+
23
from six import unichr
4+
35
from .error import LanguageError
46

57
__all__ = ['Token', 'Lexer', 'TokenKind',

‎graphql/core/language/parser.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from six import string_types
2+
23
from . import ast
34
from .error import LanguageError
45
from .lexer import Lexer, TokenKind, get_token_desc, get_token_kind_desc

‎graphql/core/language/printer.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
23
from .visitor import Visitor, visit
34

45
__all__ = ['print_ast']

‎graphql/core/language/visitor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from copy import copy
22

33
import six
4+
45
from . import ast
56
from .visitor_meta import QUERY_DOCUMENT_KEYS, VisitorMeta
67

7-
88
BREAK = object()
99
REMOVE = object()
1010

‎graphql/core/language/visitor_meta.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747

4848
class VisitorMeta(type):
49+
4950
def __new__(cls, name, bases, attrs):
5051
enter_handlers = {}
5152
leave_handlers = {}

‎graphql/core/pyutils/defer.py

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
# THE SOFTWARE.
6262
import collections
6363
import sys
64+
6465
from six import reraise
6566

6667
__all__ = ("Deferred", "AlreadyCalledDeferred", "DeferredException",
@@ -511,6 +512,7 @@ def _cb_deferred(self, result, key, succeeded):
511512

512513

513514
class DeferredDict(_ResultCollector):
515+
514516
def __init__(self, mapping):
515517
super(DeferredDict, self).__init__()
516518
assert isinstance(mapping, collections.Mapping)
@@ -519,6 +521,7 @@ def __init__(self, mapping):
519521

520522

521523
class DeferredList(_ResultCollector):
524+
522525
def __init__(self, sequence):
523526
super(DeferredList, self).__init__()
524527
assert isinstance(sequence, collections.Sequence)

‎graphql/core/type/definition.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import collections
22
import copy
33
import re
4+
45
from ..language import ast
56

67

@@ -466,7 +467,8 @@ def define_types(union_type, types):
466467
if callable(types):
467468
types = types()
468469

469-
assert isinstance(types, (list, tuple)) and len(types) > 0, 'Must provide types for Union {}.'.format(union_type.name)
470+
assert isinstance(types, (list, tuple)) and len(
471+
types) > 0, 'Must provide types for Union {}.'.format(union_type.name)
470472
has_resolve_type_fn = callable(union_type._resolve_type)
471473

472474
for type in types:

‎graphql/core/type/introspection.py

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
from collections import OrderedDict
2+
23
from ..language.printer import print_ast
34
from ..utils.ast_from_value import ast_from_value
4-
from .definition import (
5-
GraphQLArgument,
6-
GraphQLEnumType,
7-
GraphQLEnumValue,
8-
GraphQLField,
9-
GraphQLInputObjectType,
10-
GraphQLInterfaceType,
11-
GraphQLList,
12-
GraphQLNonNull,
13-
GraphQLObjectType,
14-
GraphQLScalarType,
15-
GraphQLUnionType,
16-
)
5+
from .definition import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue,
6+
GraphQLField, GraphQLInputObjectType,
7+
GraphQLInterfaceType, GraphQLList, GraphQLNonNull,
8+
GraphQLObjectType, GraphQLScalarType,
9+
GraphQLUnionType)
1710
from .scalars import GraphQLBoolean, GraphQLString
1811

1912
__Schema = GraphQLObjectType(

‎graphql/core/type/scalars.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
from six import text_type
2-
from ..language.ast import (
3-
BooleanValue,
4-
FloatValue,
5-
IntValue,
6-
StringValue,
7-
)
2+
3+
from ..language.ast import BooleanValue, FloatValue, IntValue, StringValue
84
from .definition import GraphQLScalarType
95

106
# Integers are only safe when between -(2^53 - 1) and 2^53 - 1 due to being

‎graphql/core/type/schema.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
from collections import OrderedDict
2-
from .definition import (
3-
GraphQLInputObjectType,
4-
GraphQLInterfaceType,
5-
GraphQLList,
6-
GraphQLNonNull,
7-
GraphQLObjectType,
8-
GraphQLUnionType,
9-
)
10-
from .directives import GraphQLDirective, GraphQLIncludeDirective, GraphQLSkipDirective
11-
from .introspection import IntrospectionSchema
2+
123
from ..utils.type_comparators import is_equal_type, is_type_sub_type_of
4+
from .definition import (GraphQLInputObjectType, GraphQLInterfaceType,
5+
GraphQLList, GraphQLNonNull, GraphQLObjectType,
6+
GraphQLUnionType)
7+
from .directives import (GraphQLDirective, GraphQLIncludeDirective,
8+
GraphQLSkipDirective)
9+
from .introspection import IntrospectionSchema
1310

1411

1512
class GraphQLSchema(object):
@@ -51,7 +48,7 @@ def __init__(self, query, mutation=None, subscription=None, directives=None):
5148
assert all(isinstance(d, GraphQLDirective) for d in directives), \
5249
'Schema directives must be List[GraphQLDirective] if provided but got: {}.'.format(
5350
directives
54-
)
51+
)
5552

5653
self._directives = directives
5754

‎graphql/core/utils/ast_from_value.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
import sys
44

55
from six import string_types
6+
67
from ..language import ast
7-
from ..type.definition import (
8-
GraphQLEnumType,
9-
GraphQLInputObjectType,
10-
GraphQLList,
11-
GraphQLNonNull,
12-
)
8+
from ..type.definition import (GraphQLEnumType, GraphQLInputObjectType,
9+
GraphQLList, GraphQLNonNull)
1310
from ..type.scalars import GraphQLFloat
1411

1512

‎graphql/core/utils/ast_to_code.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ def ast_to_code(ast, indent=0):
77
Converts an ast into a python code representation of the AST.
88
"""
99
code = []
10-
append = lambda line: code.append((' ' * indent) + line)
10+
11+
def append(line):
12+
code.append((' ' * indent) + line)
1113

1214
if isinstance(ast, Node):
1315
append('ast.{}('.format(ast.__class__.__name__))

‎graphql/core/utils/build_ast_schema.py

+10-22
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
from collections import OrderedDict
22

33
from ..language import ast
4-
from ..type import (
5-
GraphQLArgument,
6-
GraphQLBoolean,
7-
GraphQLEnumType,
8-
GraphQLEnumValue,
9-
GraphQLField,
10-
GraphQLFloat,
11-
GraphQLID,
12-
GraphQLInputObjectField,
13-
GraphQLInputObjectType,
14-
GraphQLInt,
15-
GraphQLInterfaceType,
16-
GraphQLList,
17-
GraphQLNonNull,
18-
GraphQLObjectType,
19-
GraphQLScalarType,
20-
GraphQLSchema,
21-
GraphQLString,
22-
GraphQLUnionType,
23-
)
4+
from ..type import (GraphQLArgument, GraphQLBoolean, GraphQLEnumType,
5+
GraphQLEnumValue, GraphQLField, GraphQLFloat, GraphQLID,
6+
GraphQLInputObjectField, GraphQLInputObjectType,
7+
GraphQLInt, GraphQLInterfaceType, GraphQLList,
8+
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
9+
GraphQLSchema, GraphQLString, GraphQLUnionType)
2410
from ..utils.value_from_ast import value_from_ast
2511

2612

@@ -41,8 +27,10 @@ def _get_inner_type_name(type_ast):
4127
return type_ast.name.value
4228

4329

44-
_false = lambda *_: False
45-
_none = lambda *_: None
30+
def _false(*_): return False
31+
32+
33+
def _none(*_): return None
4634

4735

4836
def build_ast_schema(document, query_type_name, mutation_type_name=None, subscription_type_name=None):

0 commit comments

Comments
 (0)