Navigation Menu

Skip to content

Commit

Permalink
Fixed PEP8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Aug 14, 2016
1 parent 9f1c5fa commit 6fa32a7
Show file tree
Hide file tree
Showing 36 changed files with 123 additions and 111 deletions.
2 changes: 2 additions & 0 deletions examples/starwars/schema.py
Expand Up @@ -22,12 +22,14 @@ def resolve_friends(self, args, *_):


class Human(graphene.ObjectType):

class Meta:
interfaces = (Character, )
home_planet = graphene.String()


class Droid(graphene.ObjectType):

class Meta:
interfaces = (Character, )
primary_function = graphene.String()
Expand Down
15 changes: 7 additions & 8 deletions graphene/relay/connection.py
Expand Up @@ -6,16 +6,15 @@

from graphql_relay import connection_from_list

from ..types import Boolean, String, List, Int
from ..types import Boolean, Int, List, String
from ..types.field import Field
from ..types.objecttype import ObjectType, ObjectTypeMeta
from ..types.options import Options
from ..types.utils import get_fields_in_type, yank_fields_from_attrs
from ..utils.is_base_type import is_base_type
from ..utils.props import props
from .node import Node, is_node

from ..types.utils import get_fields_in_type, yank_fields_from_attrs


class PageInfo(ObjectType):
has_next_page = Boolean(
Expand Down Expand Up @@ -66,7 +65,6 @@ def __new__(cls, name, bases, attrs):
if not options.name:
options.name = '{}Connection'.format(base_name)


edge_class = attrs.pop('Edge', None)
edge_fields = OrderedDict([
('node', Field(options.node, description='The item at the end of the edge')),
Expand All @@ -75,28 +73,29 @@ def __new__(cls, name, bases, attrs):
edge_attrs = props(edge_class) if edge_class else OrderedDict()
extended_edge_fields = get_fields_in_type(ObjectType, edge_attrs)
edge_fields.update(extended_edge_fields)
EdgeMeta = type('Meta', (object, ), {
edge_meta = type('Meta', (object, ), {
'fields': edge_fields,
'name': '{}Edge'.format(base_name)
})
yank_fields_from_attrs(edge_attrs, extended_edge_fields)
Edge = type('Edge', (ObjectType,), dict(edge_attrs, Meta=EdgeMeta))
edge = type('Edge', (ObjectType,), dict(edge_attrs, Meta=edge_meta))

options.local_fields = OrderedDict([
('page_info', Field(PageInfo, name='pageInfo', required=True)),
('edges', Field(List(Edge)))
('edges', Field(List(edge)))
])
typed_fields = get_fields_in_type(ObjectType, attrs)
options.local_fields.update(typed_fields)
options.fields = options.local_fields
yank_fields_from_attrs(attrs, typed_fields)

return type.__new__(cls, name, bases, dict(attrs, _meta=options, Edge=Edge))
return type.__new__(cls, name, bases, dict(attrs, _meta=options, Edge=edge))


class Connection(six.with_metaclass(ConnectionMeta, ObjectType)):
pass


class IterableConnectionField(Field):

def __init__(self, type, *args, **kwargs):
Expand Down
10 changes: 5 additions & 5 deletions graphene/relay/mutation.py
@@ -1,14 +1,13 @@
import re
from functools import partial

import six
import re

from promise import Promise

from ..types import Argument, Field, InputObjectType, String
from ..types.objecttype import ObjectType, ObjectTypeMeta
from ..utils.is_base_type import is_base_type
from ..utils.props import props
from ..types import Field, String, InputObjectType, Argument
from ..types.objecttype import ObjectType, ObjectTypeMeta


class ClientIDMutationMeta(ObjectTypeMeta):
Expand All @@ -23,7 +22,7 @@ def __new__(cls, name, bases, attrs):
base_name = re.sub('Payload$', '', name)
cls = ObjectTypeMeta.__new__(cls, '{}Payload'.format(base_name), bases, attrs)
mutate_and_get_payload = getattr(cls, 'mutate_and_get_payload', None)
if cls.mutate and cls.mutate.__func__ == ClientIDMutation.mutate.__func__:
if cls.mutate and cls.mutate.__func__ == ClientIDMutation.mutate.__func__:
assert mutate_and_get_payload, (
"{}.mutate_and_get_payload method is required"
" in a ClientIDMutation."
Expand All @@ -36,6 +35,7 @@ def __new__(cls, name, bases, attrs):


class ClientIDMutation(six.with_metaclass(ClientIDMutationMeta, ObjectType)):

@classmethod
def mutate(cls, root, args, context, info):
input = args.get('input')
Expand Down
10 changes: 6 additions & 4 deletions graphene/relay/node.py
@@ -1,9 +1,10 @@
import six
from collections import OrderedDict
from functools import partial

import six

from graphql_relay import from_global_id, to_global_id
from ..types import ObjectType, Interface, ID, Field

from ..types import ID, Field, Interface, ObjectType
from ..types.interface import InterfaceMeta


Expand All @@ -27,6 +28,7 @@ class Meta:


class GlobalID(Field):

def __init__(self, node, *args, **kwargs):
super(GlobalID, self).__init__(ID, *args, **kwargs)
self.node = node
Expand All @@ -52,7 +54,7 @@ class Node(six.with_metaclass(NodeMeta, Interface)):
'''An object with an ID'''

@classmethod
def Field(cls):
def Field(cls): # noqa: N802
def resolve_node(root, args, context, info):
return cls.get_node_from_global_id(args.get('id'), context, info)

Expand Down
3 changes: 2 additions & 1 deletion graphene/relay/tests/test_connection.py
@@ -1,10 +1,11 @@

from ...types import ObjectType, Schema, List, Field, String, NonNull
from ...types import Field, List, NonNull, ObjectType, Schema, String
from ..connection import Connection, PageInfo
from ..node import Node


class MyObject(ObjectType):

class Meta:
interfaces = [Node]
field = String()
Expand Down
3 changes: 2 additions & 1 deletion graphene/relay/tests/test_mutation.py
@@ -1,6 +1,7 @@
import pytest

from ...types import ObjectType, Schema, Field, InputField, InputObjectType, Argument
from ...types import (Argument, Field, InputField, InputObjectType, ObjectType,
Schema)
from ...types.scalars import String
from ..mutation import ClientIDMutation

Expand Down
3 changes: 3 additions & 0 deletions graphene/relay/tests/test_node.py
Expand Up @@ -8,6 +8,7 @@


class MyNode(ObjectType):

class Meta:
interfaces = (Node, )
name = String()
Expand All @@ -27,6 +28,7 @@ class RootQuery(ObjectType):
def test_node_no_get_node():
with pytest.raises(AssertionError) as excinfo:
class MyNode(ObjectType):

class Meta:
interfaces = (Node, )

Expand All @@ -36,6 +38,7 @@ class Meta:
def test_node_no_get_node_with_meta():
with pytest.raises(AssertionError) as excinfo:
class MyNode(ObjectType):

class Meta:
interfaces = (Node, )

Expand Down
5 changes: 4 additions & 1 deletion graphene/relay/tests/test_node_custom.py
@@ -1,11 +1,12 @@
from graphql import graphql

from ...types import ObjectType, Interface, Schema
from ...types import Interface, ObjectType, Schema
from ...types.scalars import Int, String
from ..node import Node


class CustomNode(Node):

class Meta:
name = 'Node'

Expand All @@ -27,12 +28,14 @@ class BasePhoto(Interface):


class User(ObjectType):

class Meta:
interfaces = [CustomNode]
name = String()


class Photo(ObjectType):

class Meta:
interfaces = [CustomNode, BasePhoto]

Expand Down
5 changes: 3 additions & 2 deletions graphene/types/__init__.py
Expand Up @@ -8,8 +8,8 @@
from .field import Field
from .inputfield import InputField
from .argument import Argument
from .dynamic import Dynamic
from .inputobjecttype import InputObjectType
from .dynamic import Dynamic

__all__ = [
'AbstractType',
Expand All @@ -28,4 +28,5 @@
'Boolean',
'List',
'NonNull',
'Argument']
'Argument'
'Dynamic']
4 changes: 2 additions & 2 deletions graphene/types/abstracttype.py
Expand Up @@ -2,8 +2,8 @@

from ..utils.is_base_type import is_base_type
from .options import Options

from .utils import get_fields_in_type, yank_fields_from_attrs, merge_fields_in_attrs
from .utils import (get_fields_in_type, merge_fields_in_attrs,
yank_fields_from_attrs)


class AbstractTypeMeta(type):
Expand Down
1 change: 1 addition & 0 deletions graphene/types/dynamic.py
@@ -1,4 +1,5 @@
import inspect

from ..utils.orderedtype import OrderedType


Expand Down
5 changes: 3 additions & 2 deletions graphene/types/enum.py
Expand Up @@ -41,14 +41,15 @@ def __call__(cls, *args, **kwargs): # noqa: N805
return cls.from_enum(PyEnum(*args, **kwargs), description=description)
return super(EnumTypeMeta, cls).__call__(*args, **kwargs)

def from_enum(cls, enum, description=None):
def from_enum(cls, enum, description=None): # noqa: N805
meta_class = type('Meta', (object,), {'enum': enum, 'description': description})
return type(meta_class.enum.__name__, (Enum,), {'Meta': meta_class})

def __str__(cls):
def __str__(cls): # noqa: N805
return cls._meta.name


class Enum(six.with_metaclass(EnumTypeMeta, UnmountedType)):

def get_type(self):
return type(self)
4 changes: 2 additions & 2 deletions graphene/types/field.py
@@ -1,10 +1,10 @@
import inspect
from collections import Mapping, OrderedDict
from functools import partial
from collections import OrderedDict, Mapping

from ..utils.orderedtype import OrderedType
from .structures import NonNull
from .argument import to_arguments
from .structures import NonNull


def source_resolver(source, root, args, context, info):
Expand Down
8 changes: 4 additions & 4 deletions graphene/types/inputobjecttype.py
@@ -1,11 +1,11 @@
import six

from ..utils.is_base_type import is_base_type
from .options import Options

from .abstracttype import AbstractTypeMeta
from .utils import get_fields_in_type, yank_fields_from_attrs, merge_fields_in_attrs
from .options import Options
from .unmountedtype import UnmountedType
from .utils import (get_fields_in_type, merge_fields_in_attrs,
yank_fields_from_attrs)


class InputObjectTypeMeta(AbstractTypeMeta):
Expand All @@ -30,7 +30,7 @@ def __new__(cls, name, bases, attrs):

return type.__new__(cls, name, bases, dict(attrs, _meta=options))

def __str__(cls):
def __str__(cls): # noqa: N802
return cls._meta.name


Expand Down
8 changes: 4 additions & 4 deletions graphene/types/interface.py
@@ -1,10 +1,10 @@
import six

from ..utils.is_base_type import is_base_type
from .options import Options

from .abstracttype import AbstractTypeMeta
from .utils import get_fields_in_type, yank_fields_from_attrs, merge_fields_in_attrs
from .options import Options
from .utils import (get_fields_in_type, merge_fields_in_attrs,
yank_fields_from_attrs)


class InterfaceMeta(AbstractTypeMeta):
Expand All @@ -29,7 +29,7 @@ def __new__(cls, name, bases, attrs):

return type.__new__(cls, name, bases, dict(attrs, _meta=options))

def __str__(cls):
def __str__(cls): # noqa: N802
return cls._meta.name


Expand Down
10 changes: 6 additions & 4 deletions graphene/types/objecttype.py
@@ -1,12 +1,13 @@
from collections import OrderedDict

import six

from ..utils.is_base_type import is_base_type
from .options import Options

from .abstracttype import AbstractTypeMeta
from .utils import get_fields_in_type, yank_fields_from_attrs, merge_fields_in_attrs
from .interface import Interface
from .options import Options
from .utils import (get_fields_in_type, merge_fields_in_attrs,
yank_fields_from_attrs)


class ObjectTypeMeta(AbstractTypeMeta):
Expand Down Expand Up @@ -45,11 +46,12 @@ def __new__(cls, name, bases, attrs):

return cls

def __str__(cls):
def __str__(cls): # noqa: N802
return cls._meta.name


class ObjectType(six.with_metaclass(ObjectTypeMeta)):

@classmethod
def is_type_of(cls, root, context, info):
if isinstance(root, cls):
Expand Down
1 change: 1 addition & 0 deletions graphene/types/options.py
@@ -1,4 +1,5 @@
import inspect

from ..utils.props import props


Expand Down
5 changes: 3 additions & 2 deletions graphene/types/scalars.py
@@ -1,6 +1,7 @@
import six

from graphql.language.ast import BooleanValue, FloatValue, IntValue, StringValue
from graphql.language.ast import (BooleanValue, FloatValue, IntValue,
StringValue)

from ..utils.is_base_type import is_base_type
from .options import Options
Expand All @@ -25,7 +26,7 @@ def __new__(cls, name, bases, attrs):

return super_new(cls, name, bases, dict(attrs, _meta=options))

def __str__(cls):
def __str__(cls): # noqa: N802
return cls._meta.name


Expand Down

0 comments on commit 6fa32a7

Please sign in to comment.