Skip to content

Commit dd0c4b5

Browse files
committed
More flake8 issues and minor clean-up
1 parent d0ee920 commit dd0c4b5

File tree

11 files changed

+50
-52
lines changed

11 files changed

+50
-52
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
2-
ignore = E203,W503,E704
2+
ignore = E203,W503,W503
33
exclude = .git,.mypy_cache,.pytest_cache,.tox,.venv,__pycache__,build,dist,docs
44
max-line-length = 88

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
__pycache__/
22
*.py[cod]
33

4-
*.so
5-
6-
# Distribution / packaging
74
.Python
85
build/
96
develop-eggs/
@@ -41,7 +38,6 @@ coverage.xml
4138
*.cover
4239
.pytest_cache/
4340

44-
# Translations
4541
*.mo
4642
*.pot
4743

graphql_relay/connection/arrayconnection.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
from .connectiontypes import Connection, PageInfo, Edge
55

66

7-
def connection_from_list(data, args=None, connection_type=None,
8-
edge_type=None, pageinfo_type=None):
9-
'''
7+
def connection_from_list(
8+
data, args=None,
9+
connection_type=None, edge_type=None, pageinfo_type=None):
10+
"""
1011
A simple function that accepts an array and connection arguments, and returns
1112
a connection object for use in GraphQL. It uses array offsets as pagination,
1213
so pagination will only work if the array is static.
13-
'''
14+
"""
1415
_len = len(data)
1516
return connection_from_list_slice(
1617
data,
@@ -25,17 +26,17 @@ def connection_from_list(data, args=None, connection_type=None,
2526

2627

2728
def connection_from_list_slice(
28-
list_slice, args=None, connection_type=None,
29-
edge_type=None, pageinfo_type=None,
29+
list_slice, args=None,
30+
connection_type=None, edge_type=None, pageinfo_type=None,
3031
slice_start=0, list_length=0, list_slice_length=None):
31-
'''
32+
"""
3233
Given a slice (subset) of an array, returns a connection object for use in
3334
GraphQL.
3435
This function is similar to `connectionFromArray`, but is intended for use
3536
cases where you know the cardinality of the connection, consider it too large
3637
to materialize the entire array, and instead wish pass in a slice of the
3738
total result large enough to cover the range specified in `args`.
38-
'''
39+
"""
3940
connection_type = connection_type or Connection
4041
edge_type = edge_type or Edge
4142
pageinfo_type = pageinfo_type or PageInfo
@@ -106,26 +107,26 @@ def connection_from_list_slice(
106107

107108

108109
def offset_to_cursor(offset):
109-
'''
110+
"""
110111
Creates the cursor string from an offset.
111-
'''
112+
"""
112113
return base64(PREFIX + str(offset))
113114

114115

115116
def cursor_to_offset(cursor):
116-
'''
117+
"""
117118
Rederives the offset from the cursor string.
118-
'''
119+
"""
119120
try:
120121
return int(unbase64(cursor)[len(PREFIX):])
121122
except binascii.Error:
122123
return None
123124

124125

125126
def cursor_for_object_in_connection(data, _object):
126-
'''
127+
"""
127128
Return the cursor associated with an object in an array.
128-
'''
129+
"""
129130
if _object not in data:
130131
return None
131132

@@ -134,11 +135,11 @@ def cursor_for_object_in_connection(data, _object):
134135

135136

136137
def get_offset_with_default(cursor=None, default_offset=0):
137-
'''
138+
"""
138139
Given an optional cursor and a default offset, returns the offset
139140
to use; if the cursor contains a valid offset, that will be used,
140141
otherwise it will be the default.
141-
'''
142+
"""
142143
if not isinstance(cursor, str):
143144
return default_offset
144145

graphql_relay/connection/tests/test_connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
'friends': GraphQLField(
3535
friendConnection,
3636
args=connection_args,
37-
resolve=lambda user, info_, **args:
37+
resolve=lambda user, _info, **args:
3838
connection_from_list(user.friends, args),
3939
),
4040
},
@@ -43,7 +43,7 @@
4343
friendEdge, friendConnection = connection_definitions(
4444
'Friend',
4545
userType,
46-
resolve_node=lambda edge, *_: allUsers[edge.node],
46+
resolve_node=lambda edge, _info: allUsers[edge.node],
4747
edge_fields=lambda: {
4848
'friendshipTime': GraphQLField(
4949
GraphQLString,
@@ -53,7 +53,7 @@
5353
connection_fields=lambda: {
5454
'totalCount': GraphQLField(
5555
GraphQLInt,
56-
resolve=lambda user_, info_: len(allUsers) - 1
56+
resolve=lambda _user, _info: len(allUsers) - 1
5757
),
5858
}
5959
)
@@ -63,7 +63,7 @@
6363
fields=lambda: {
6464
'user': GraphQLField(
6565
userType,
66-
resolve=lambda root_, info_: allUsers[0]
66+
resolve=lambda _root, _info: allUsers[0]
6767
),
6868
}
6969
)

graphql_relay/node/node.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def node_definitions(id_fetcher, type_resolver=None):
13-
'''
13+
"""
1414
Given a function to map from an ID to an underlying object, and a function
1515
to map from an underlying object to the concrete GraphQLObjectType it
1616
corresponds to, constructs a `Node` interface that objects can implement,
@@ -19,7 +19,7 @@ def node_definitions(id_fetcher, type_resolver=None):
1919
If the type_resolver is omitted, object resolution on the interface will be
2020
handled with the `is_type_of` method on object types, as with any GraphQL
2121
interface without a provided `resolve_type` method.
22-
'''
22+
"""
2323
node_interface = GraphQLInterfaceType(
2424
'Node',
2525
description='An object with an ID',
@@ -37,36 +37,36 @@ def node_definitions(id_fetcher, type_resolver=None):
3737
'id': GraphQLArgument(
3838
GraphQLNonNull(GraphQLID),
3939
description='The ID of an object')},
40-
resolve=lambda obj, info, id: id_fetcher(id, info)
40+
resolve=lambda _obj, info, id: id_fetcher(id, info)
4141
)
4242
return node_interface, node_field
4343

4444

4545
def to_global_id(type_, id_):
46-
'''
46+
"""
4747
Takes a type name and an ID specific to that type name, and returns a
4848
"global ID" that is unique among all types.
49-
'''
49+
"""
5050
return base64(':'.join([type_, str(id_)]))
5151

5252

5353
def from_global_id(global_id):
54-
'''
54+
"""
5555
Takes the "global ID" created by toGlobalID, and retuns the type name and ID
5656
used to create it.
57-
'''
57+
"""
5858
unbased_global_id = unbase64(global_id)
5959
_type, _id = unbased_global_id.split(':', 1)
6060
return _type, _id
6161

6262

6363
def global_id_field(type_name, id_fetcher=None):
64-
'''
64+
"""
6565
Creates the configuration for an id field on a node, using `to_global_id` to
6666
construct the ID from the provided typename. The type-specific ID is fetcher
6767
by calling id_fetcher on the object, or if not provided, by accessing the `id`
6868
property on the object.
69-
'''
69+
"""
7070
return GraphQLField(
7171
GraphQLNonNull(GraphQLID),
7272
description='The ID of an object',

graphql_relay/node/tests/test_global.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
}
2929

3030

31-
def get_node(global_id, *args):
31+
def get_node(global_id, _info):
3232
_type, _id = from_global_id(global_id)
3333
if _type == 'User':
3434
return userData[_id]
3535
else:
3636
return photoData[_id]
3737

3838

39-
def get_node_type(obj, context, info):
39+
def get_node_type(obj, _info, _type):
4040
if isinstance(obj, User):
4141
return userType
4242
else:

graphql_relay/node/tests/test_plural.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def resolve_single_input(info, username):
3838

3939
schema = GraphQLSchema(query=queryType)
4040

41-
RootValue = namedtuple('RootValue', ['lang'])
4241

43-
root_value = RootValue(lang='en')
42+
class RootValue:
43+
lang = 'en'
4444

4545

4646
@mark.asyncio
@@ -69,7 +69,7 @@ async def test_allows_fetching():
6969
},
7070
]
7171
}
72-
result = await graphql(schema, query, root_value=root_value)
72+
result = await graphql(schema, query, root_value=RootValue())
7373
assert not result.errors
7474
assert result.data == expected
7575

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def run_tests(self):
4646
license='MIT',
4747

4848
classifiers=[
49-
'Development Status :: 3 - Alpha',
49+
'Development Status :: 5 - Production/Stable',
5050
'Intended Audience :: Developers',
5151
'Topic :: Software Development :: Libraries',
5252
"License :: OSI Approved :: MIT License",
@@ -56,14 +56,14 @@ def run_tests(self):
5656
'Programming Language :: Python :: Implementation :: PyPy',
5757
],
5858

59-
keywords='graphql relay api ',
59+
keywords='graphql relay api',
6060

6161
packages=find_packages(exclude=['tests']),
6262

6363
install_requires=[
6464
'graphql-core-next>=1.0.5',
6565
],
66-
tests_require=['pytest', 'pytest-asyncio'],
66+
tests_require=['pytest>=5', 'pytest-asyncio>=0.10'],
6767
extras_require={},
6868

6969
cmdclass={'test': PyTest},

tests/starwars/data.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# This defines a basic set of data for our Star Wars Schema.
2-
#
3-
# This data is hard coded for the sake of the demo, but you could imagine
4-
# fetching this data from a backend service rather than from hardcoded
5-
# JSON objects in a more complex demo.
1+
"""This defines a basic set of data for our Star Wars Schema.
2+
3+
This data is hard coded for the sake of the demo, but you could imagine
4+
fetching this data from a backend service rather than from hardcoded
5+
JSON objects in a more complex demo.
6+
"""
67

78
from collections import namedtuple
89

tests/starwars/test_mutations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
@mark.asyncio
9-
async def test_correctely_mutates_dataset():
9+
async def test_correctly_mutates_dataset():
1010
query = '''
1111
mutation AddBWingQuery($input: IntroduceShipInput!) {
1212
introduceShip(input: $input) {

0 commit comments

Comments
 (0)