Skip to content

Commit bc00463

Browse files
committed
Fixed pep8 errors
1 parent 6449bbc commit bc00463

File tree

10 files changed

+64
-40
lines changed

10 files changed

+64
-40
lines changed

examples/flask_sqlalchemy/schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import graphene
22
from graphene import relay
3-
from graphene_sqlalchemy import (SQLAlchemyConnectionField,
4-
SQLAlchemyObjectType)
3+
from graphene_sqlalchemy import SQLAlchemyConnectionField, SQLAlchemyObjectType
54
from models import Department as DepartmentModel
65
from models import Employee as EmployeeModel
76
from models import Role as RoleModel

graphene_sqlalchemy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
SQLAlchemyConnectionField
66
)
77
from .utils import (
8-
get_query,
9-
get_session
8+
get_query,
9+
get_session
1010
)
1111

1212
__all__ = ['SQLAlchemyObjectType',

graphene_sqlalchemy/converter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from singledispatch import singledispatch
22
from sqlalchemy import types
3-
from sqlalchemy.orm import interfaces
43
from sqlalchemy.dialects import postgresql
4+
from sqlalchemy.orm import interfaces
55

6-
from graphene import Enum, ID, Boolean, Float, Int, String, List, Field, Dynamic
6+
from graphene import (ID, Boolean, Dynamic, Enum, Field, Float, Int, List,
7+
String)
78
from graphene.relay import is_node
89
from graphene.types.json import JSONString
10+
911
from .fields import SQLAlchemyConnectionField
1012

1113
try:

graphene_sqlalchemy/fields.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from functools import partial
2+
23
from sqlalchemy.orm.query import Query
34

45
from graphene.relay import ConnectionField
56
from graphene.relay.connection import PageInfo
67
from graphql_relay.connection.arrayconnection import connection_from_list_slice
8+
79
from .utils import get_query
810

911

graphene_sqlalchemy/registry.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
class Registry(object):
2+
23
def __init__(self):
34
self._registry = {}
45
self._registry_models = {}
56
self._registry_composites = {}
67

78
def register(self, cls):
89
from .types import SQLAlchemyObjectType
9-
assert issubclass(cls, SQLAlchemyObjectType), 'Only SQLAlchemyObjectType can be registered, received "{}"'.format(cls.__name__)
10+
assert issubclass(
11+
cls, SQLAlchemyObjectType), 'Only SQLAlchemyObjectType can be registered, received "{}"'.format(
12+
cls.__name__)
1013
assert cls._meta.registry == self, 'Registry for a Model have to match.'
1114
# assert self.get_type_for_model(cls._meta.model) in [None, cls], (
1215
# 'SQLAlchemy model "{}" already associated with '

graphene_sqlalchemy/tests/test_converter.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
from py.test import raises
22
from sqlalchemy import Column, Table, types
3-
from sqlalchemy.orm import composite
3+
from sqlalchemy.dialects import postgresql
44
from sqlalchemy.ext.declarative import declarative_base
5+
from sqlalchemy.orm import composite
56
from sqlalchemy_utils import ChoiceType, ScalarListType
6-
from sqlalchemy.dialects import postgresql
77

88
import graphene
99
from graphene.relay import Node
1010
from graphene.types.json import JSONString
11+
1112
from ..converter import (convert_sqlalchemy_column,
1213
convert_sqlalchemy_composite,
1314
convert_sqlalchemy_relationship)
1415
from ..fields import SQLAlchemyConnectionField
15-
from ..types import SQLAlchemyObjectType
1616
from ..registry import Registry
17-
17+
from ..types import SQLAlchemyObjectType
1818
from .models import Article, Pet, Reporter
1919

2020

@@ -136,6 +136,7 @@ def test_should_manytomany_convert_connectionorlist():
136136

137137
def test_should_manytomany_convert_connectionorlist_list():
138138
class A(SQLAlchemyObjectType):
139+
139140
class Meta:
140141
model = Pet
141142

@@ -149,6 +150,7 @@ class Meta:
149150

150151
def test_should_manytomany_convert_connectionorlist_connection():
151152
class A(SQLAlchemyObjectType):
153+
152154
class Meta:
153155
model = Pet
154156
interfaces = (Node, )
@@ -167,6 +169,7 @@ def test_should_manytoone_convert_connectionorlist():
167169

168170
def test_should_manytoone_convert_connectionorlist_list():
169171
class A(SQLAlchemyObjectType):
172+
170173
class Meta:
171174
model = Reporter
172175

@@ -179,6 +182,7 @@ class Meta:
179182

180183
def test_should_manytoone_convert_connectionorlist_connection():
181184
class A(SQLAlchemyObjectType):
185+
182186
class Meta:
183187
model = Reporter
184188
interfaces = (Node, )
@@ -192,6 +196,7 @@ class Meta:
192196

193197
def test_should_onetoone_convert_field():
194198
class A(SQLAlchemyObjectType):
199+
195200
class Meta:
196201
model = Article
197202
interfaces = (Node, )
@@ -230,6 +235,7 @@ def test_should_postgresql_hstore_convert():
230235
def test_should_composite_convert():
231236

232237
class CompositeClass(object):
238+
233239
def __init__(self, col1, col2):
234240
self.col1 = col1
235241
self.col2 = col2
@@ -253,6 +259,7 @@ def test_should_unknown_sqlalchemy_composite_raise_exception():
253259
with raises(Exception) as excinfo:
254260

255261
class CompositeClass(object):
262+
256263
def __init__(self, col1, col2):
257264
self.col1 = col1
258265
self.col2 = col2

graphene_sqlalchemy/tests/test_query.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
import graphene
66
from graphene.relay import Node
7-
from ..types import SQLAlchemyObjectType
8-
from ..fields import SQLAlchemyConnectionField
97

8+
from ..fields import SQLAlchemyConnectionField
9+
from ..types import SQLAlchemyObjectType
1010
from .models import Article, Base, Editor, Reporter
1111

1212
db = create_engine('sqlite:///test_sqlalchemy.sqlite3')
@@ -250,7 +250,6 @@ class Meta:
250250
model = Editor
251251
interfaces = (Node, )
252252

253-
254253
class ReporterNode(SQLAlchemyObjectType):
255254

256255
class Meta:
@@ -268,6 +267,7 @@ class Meta:
268267
interfaces = (Node, )
269268

270269
class CreateArticle(graphene.Mutation):
270+
271271
class Input:
272272
headline = graphene.String()
273273
reporter_id = graphene.ID()
@@ -279,7 +279,7 @@ class Input:
279279
def mutate(cls, instance, args, context, info):
280280
new_article = Article(
281281
headline=args.get('headline'),
282-
reporter_id = args.get('reporter_id'),
282+
reporter_id=args.get('reporter_id'),
283283
)
284284

285285
session.add(new_article)

graphene_sqlalchemy/tests/test_schema.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from py.test import raises
22

3+
from ..registry import Registry
34
from ..types import SQLAlchemyObjectType
4-
55
from .models import Reporter
6-
from ..registry import Registry
76

87

98
def test_should_raise_if_no_model():
@@ -16,6 +15,7 @@ class Character1(SQLAlchemyObjectType):
1615
def test_should_raise_if_model_is_invalid():
1716
with raises(Exception) as excinfo:
1817
class Character2(SQLAlchemyObjectType):
18+
1919
class Meta:
2020
model = 1
2121
assert 'valid SQLAlchemy Model' in str(excinfo.value)
@@ -28,7 +28,15 @@ class Meta:
2828
model = Reporter
2929
registry = Registry()
3030

31-
assert list(ReporterType2._meta.fields.keys()) == ['id', 'first_name', 'last_name', 'email', 'pets', 'articles', 'favorite_article']
31+
assert list(
32+
ReporterType2._meta.fields.keys()) == [
33+
'id',
34+
'first_name',
35+
'last_name',
36+
'email',
37+
'pets',
38+
'articles',
39+
'favorite_article']
3240

3341

3442
def test_should_map_only_few_fields():

graphene_sqlalchemy/tests/test_types.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
from graphql.type import GraphQLObjectType, GraphQLInterfaceType
2-
from graphql import GraphQLInt
3-
from pytest import raises
41

5-
from graphene import Schema, Interface, ObjectType
2+
from graphene import Field, Int, Interface, ObjectType
63
from graphene.relay import Node, is_node
7-
from ..types import SQLAlchemyObjectType
8-
from ..registry import Registry
9-
10-
from graphene import Field, Int
114

5+
from ..registry import Registry
6+
from ..types import SQLAlchemyObjectType
127
from .models import Article, Reporter
138

149
registry = Registry()
@@ -48,7 +43,15 @@ def test_sqlalchemy_interface():
4843
def test_objecttype_registered():
4944
assert issubclass(Character, ObjectType)
5045
assert Character._meta.model == Reporter
51-
assert list(Character._meta.fields.keys()) == ['id', 'first_name', 'last_name', 'email', 'pets', 'articles', 'favorite_article']
46+
assert list(
47+
Character._meta.fields.keys()) == [
48+
'id',
49+
'first_name',
50+
'last_name',
51+
'email',
52+
'pets',
53+
'articles',
54+
'favorite_article']
5255

5356

5457
# def test_sqlalchemynode_idfield():

graphene_sqlalchemy/types.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
from collections import OrderedDict
2+
23
import six
34
from sqlalchemy.inspection import inspect as sqlalchemyinspect
45
from sqlalchemy.orm.exc import NoResultFound
56

6-
from graphene import ObjectType, Field
7+
from graphene import Field, ObjectType
78
from graphene.relay import is_node
9+
from graphene.types.objecttype import ObjectTypeMeta
10+
from graphene.types.options import Options
11+
from graphene.types.utils import merge, yank_fields_from_attrs
12+
from graphene.utils.is_base_type import is_base_type
13+
814
from .converter import (convert_sqlalchemy_column,
915
convert_sqlalchemy_composite,
1016
convert_sqlalchemy_relationship)
11-
from .utils import is_mapped
12-
13-
from graphene.types.objecttype import ObjectTypeMeta
14-
from graphene.types.options import Options
1517
from .registry import Registry, get_global_registry
16-
from graphene.utils.is_base_type import is_base_type
17-
from graphene.types.utils import yank_fields_from_attrs, merge
18-
from .utils import get_query
18+
from .utils import get_query, is_mapped
1919

2020

2121
def construct_fields(options):
@@ -96,7 +96,6 @@ def __new__(cls, name, bases, attrs):
9696
'{}.Meta, received "{}".'
9797
).format(name, options.model)
9898

99-
10099
cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options))
101100

102101
options.registry.register(cls)
@@ -116,6 +115,7 @@ def __new__(cls, name, bases, attrs):
116115

117116

118117
class SQLAlchemyObjectType(six.with_metaclass(SQLAlchemyObjectTypeMeta, ObjectType)):
118+
119119
@classmethod
120120
def is_type_of(cls, root, context, info):
121121
if isinstance(root, cls):
@@ -124,7 +124,7 @@ def is_type_of(cls, root, context, info):
124124
raise Exception((
125125
'Received incompatible instance "{}".'
126126
).format(root))
127-
return type(root) == cls._meta.model
127+
return isinstance(root, cls._meta.model)
128128

129129
@classmethod
130130
def get_query(cls, context):
@@ -138,8 +138,8 @@ def get_node(cls, id, context, info):
138138
except NoResultFound:
139139
return None
140140

141-
def resolve_id(root, args, context, info):
141+
def resolve_id(self, args, context, info):
142142
graphene_type = info.parent_type.graphene_type
143143
if is_node(graphene_type):
144-
return root.__mapper__.primary_key_from_instance(root)[0]
145-
return getattr(root, graphene_type._meta.id, None)
144+
return self.__mapper__.primary_key_from_instance(self)[0]
145+
return getattr(self, graphene_type._meta.id, None)

0 commit comments

Comments
 (0)