Skip to content

Commit 9e7d46d

Browse files
committed
Fix flake8 issues
1 parent eab7a2f commit 9e7d46d

File tree

9 files changed

+62
-62
lines changed

9 files changed

+62
-62
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ __pycache__/
99
# Distribution / packaging
1010
.Python
1111
env/
12+
venv/
13+
.venv/
1214
build/
1315
develop-eggs/
1416
dist/
@@ -67,4 +69,4 @@ target/
6769
.idea/
6870
.vscode/
6971

70-
*.sqlite3
72+
*.sqlite3

graphql_ws/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88

99

1010
from .base import BaseConnectionContext, BaseSubscriptionServer
11+
12+
__all__ = ['BaseConnectionContext', 'BaseSubscriptionServer']

graphql_ws/aiohttp.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
from inspect import isawaitable, isasyncgen
1+
from inspect import isawaitable
22
from asyncio import ensure_future, wait, shield
33

44
from aiohttp import WSMsgType
55
from graphql.execution.executors.asyncio import AsyncioExecutor
66

7-
from .base import ConnectionClosedException, BaseConnectionContext, BaseSubscriptionServer
7+
from .base import (
8+
ConnectionClosedException, BaseConnectionContext, BaseSubscriptionServer)
89
from .observable_aiter import setup_observable_extension
910

1011
from .constants import (
@@ -49,7 +50,8 @@ def __init__(self, schema, keep_alive=True, loop=None):
4950
def get_graphql_params(self, *args, **kwargs):
5051
params = super(AiohttpSubscriptionServer,
5152
self).get_graphql_params(*args, **kwargs)
52-
return dict(params, return_promise=True, executor=AsyncioExecutor(loop=self.loop))
53+
return dict(params, return_promise=True,
54+
executor=AsyncioExecutor(loop=self.loop))
5355

5456
async def _handle(self, ws, request_context=None):
5557
connection_context = AiohttpConnectionContext(ws, request_context)
@@ -104,14 +106,16 @@ async def on_start(self, connection_context, op_id, params):
104106
execution_result = await execution_result
105107

106108
if not hasattr(execution_result, '__aiter__'):
107-
await self.send_execution_result(connection_context, op_id, execution_result)
109+
await self.send_execution_result(
110+
connection_context, op_id, execution_result)
108111
else:
109112
iterator = await execution_result.__aiter__()
110113
connection_context.register_operation(op_id, iterator)
111114
async for single_result in iterator:
112115
if not connection_context.has_operation(op_id):
113116
break
114-
await self.send_execution_result(connection_context, op_id, single_result)
117+
await self.send_execution_result(
118+
connection_context, op_id, single_result)
115119
await self.send_message(connection_context, op_id, GQL_COMPLETE)
116120

117121
async def on_stop(self, connection_context, op_id):

graphql_ws/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
from collections import OrderedDict
33

44
from graphql import graphql, format_error
5-
from graphql.execution import ExecutionResult
65

76
from .constants import (
87
GQL_CONNECTION_INIT,
98
GQL_CONNECTION_TERMINATE,
109
GQL_START,
1110
GQL_STOP,
12-
GQL_COMPLETE,
1311
GQL_ERROR,
1412
GQL_CONNECTION_ERROR,
1513
GQL_DATA
@@ -93,7 +91,8 @@ def process_message(self, connection_context, parsed_message):
9391
params = self.get_graphql_params(connection_context, payload)
9492
if not isinstance(params, dict):
9593
error = Exception(
96-
"Invalid params returned from get_graphql_params! return values must be a dict.")
94+
"Invalid params returned from get_graphql_params!"
95+
" Return values must be a dict.")
9796
return self.send_error(connection_context, op_id, error)
9897

9998
# If we already have a subscription with this id, unsubscribe from
@@ -107,8 +106,8 @@ def process_message(self, connection_context, parsed_message):
107106
return self.on_stop(connection_context, op_id)
108107

109108
else:
110-
return self.send_error(connection_context, op_id,
111-
Exception('Invalid message type: {}.'.format(op_type)))
109+
return self.send_error(connection_context, op_id, Exception(
110+
"Invalid message type: {}.".format(op_type)))
112111

113112
def send_execution_result(self, connection_context, op_id, execution_result):
114113
result = self.execution_result_to_dict(execution_result)

graphql_ws/django_channels.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
1-
from channels.generic.websockets import JsonWebsocketConsumer
2-
from .base import BaseConnectionContext
31
import json
4-
from graphql.execution.executors.sync import SyncExecutor
5-
from .base import (
6-
ConnectionClosedException,
7-
BaseConnectionContext,
8-
BaseSubscriptionServer
9-
)
10-
from .constants import (
11-
GQL_CONNECTION_ACK,
12-
GQL_CONNECTION_ERROR
13-
)
14-
from django.conf import settings
2+
153
from rx import Observer, Observable
16-
from django.conf import settings
4+
from graphql.execution.executors.sync import SyncExecutor
5+
6+
from channels.generic.websockets import JsonWebsocketConsumer
177
from graphene_django.settings import graphene_settings
188

9+
from .base import BaseConnectionContext, BaseSubscriptionServer
10+
from .constants import GQL_CONNECTION_ACK, GQL_CONNECTION_ERROR
11+
12+
1913
class DjangoChannelConnectionContext(BaseConnectionContext):
20-
21-
def __init__(self, message, request_context = None):
14+
15+
def __init__(self, message, request_context=None):
2216
self.message = message
2317
self.operations = {}
2418
self.request_context = request_context
2519

2620
def send(self, data):
2721
self.message.reply_channel.send(data)
28-
22+
2923
def close(self, reason):
3024
data = {
3125
'close': True,
3226
'text': reason
3327
}
3428
self.message.reply_channel.send(data)
3529

30+
3631
class DjangoChannelSubscriptionServer(BaseSubscriptionServer):
3732

3833
def get_graphql_params(self, *args, **kwargs):
@@ -74,8 +69,8 @@ def on_start(self, connection_context, op_id, params):
7469
try:
7570
execution_result = self.execute(
7671
connection_context.request_context, params)
77-
assert isinstance(
78-
execution_result, Observable), "A subscription must return an observable"
72+
assert isinstance(execution_result, Observable), \
73+
"A subscription must return an observable"
7974
execution_result.subscribe(SubscriptionObserver(
8075
connection_context,
8176
op_id,
@@ -99,23 +94,25 @@ class GraphQLSubscriptionConsumer(JsonWebsocketConsumer):
9994
http_user_and_session = True
10095
strict_ordering = True
10196

102-
def connect(self, message, **kwargs):
97+
def connect(self, message, **_kwargs):
10398
message.reply_channel.send({"accept": True})
10499

105-
106-
def receive(self, content, **kwargs):
100+
def receive(self, content, **_kwargs):
107101
"""
108102
Called when a message is received with either text or bytes
109103
filled out.
110104
"""
111105
self.connection_context = DjangoChannelConnectionContext(self.message)
112-
self.subscription_server = DjangoChannelSubscriptionServer(graphene_settings.SCHEMA)
106+
self.subscription_server = DjangoChannelSubscriptionServer(
107+
graphene_settings.SCHEMA)
113108
self.subscription_server.on_open(self.connection_context)
114109
self.subscription_server.handle(content, self.connection_context)
115110

111+
116112
class SubscriptionObserver(Observer):
117113

118-
def __init__(self, connection_context, op_id, send_execution_result, send_error, on_close):
114+
def __init__(self, connection_context, op_id,
115+
send_execution_result, send_error, on_close):
119116
self.connection_context = connection_context
120117
self.op_id = op_id
121118
self.send_execution_result = send_execution_result

graphql_ws/gevent.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
from __future__ import absolute_import
22

3-
import json
4-
5-
from graphql import format_error, graphql
6-
from graphql.execution.executors.sync import SyncExecutor
73
from rx import Observer, Observable
4+
from graphql.execution.executors.sync import SyncExecutor
5+
86
from .base import (
9-
ConnectionClosedException,
10-
BaseConnectionContext,
11-
BaseSubscriptionServer
12-
)
13-
from .constants import (
14-
GQL_CONNECTION_ACK,
15-
GQL_CONNECTION_ERROR
16-
)
7+
ConnectionClosedException, BaseConnectionContext, BaseSubscriptionServer)
8+
from .constants import GQL_CONNECTION_ACK, GQL_CONNECTION_ERROR
179

1810

1911
class GeventConnectionContext(BaseConnectionContext):
@@ -79,8 +71,8 @@ def on_start(self, connection_context, op_id, params):
7971
try:
8072
execution_result = self.execute(
8173
connection_context.request_context, params)
82-
assert isinstance(
83-
execution_result, Observable), "A subscription must return an observable"
74+
assert isinstance(execution_result, Observable), \
75+
"A subscription must return an observable"
8476
execution_result.subscribe(SubscriptionObserver(
8577
connection_context,
8678
op_id,
@@ -97,7 +89,8 @@ def on_stop(self, connection_context, op_id):
9789

9890
class SubscriptionObserver(Observer):
9991

100-
def __init__(self, connection_context, op_id, send_execution_result, send_error, on_close):
92+
def __init__(self, connection_context, op_id,
93+
send_execution_result, send_error, on_close):
10194
self.connection_context = connection_context
10295
self.op_id = op_id
10396
self.send_execution_result = send_execution_result

graphql_ws/observable_aiter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
from asyncio import Future
12

2-
from asyncio import Future, get_event_loop
33
from rx.internal import extensionmethod
44
from rx.core import Observable
55

graphql_ws/websockets_lib.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
from inspect import isawaitable
2-
32
from asyncio import ensure_future, wait, shield
43
from websockets import ConnectionClosed
54
from graphql.execution.executors.asyncio import AsyncioExecutor
65

7-
from .base import ConnectionClosedException, BaseConnectionContext, BaseSubscriptionServer
6+
from .base import (
7+
ConnectionClosedException, BaseConnectionContext, BaseSubscriptionServer)
88
from .observable_aiter import setup_observable_extension
99

1010
from .constants import (
11-
GQL_CONNECTION_ACK,
12-
GQL_CONNECTION_ERROR,
13-
GQL_COMPLETE
14-
)
11+
GQL_CONNECTION_ACK, GQL_CONNECTION_ERROR, GQL_COMPLETE)
1512

1613
setup_observable_extension()
1714

@@ -45,7 +42,8 @@ def __init__(self, schema, keep_alive=True, loop=None):
4542
def get_graphql_params(self, *args, **kwargs):
4643
params = super(WsLibSubscriptionServer,
4744
self).get_graphql_params(*args, **kwargs)
48-
return dict(params, return_promise=True, executor=AsyncioExecutor(loop=self.loop))
45+
return dict(params, return_promise=True,
46+
executor=AsyncioExecutor(loop=self.loop))
4947

5048
async def _handle(self, ws, request_context):
5149
connection_context = WsLibConnectionContext(ws, request_context)
@@ -87,9 +85,11 @@ async def on_connect(self, connection_context, payload):
8785
async def on_connection_init(self, connection_context, op_id, payload):
8886
try:
8987
await self.on_connect(connection_context, payload)
90-
await self.send_message(connection_context, op_type=GQL_CONNECTION_ACK)
88+
await self.send_message(
89+
connection_context, op_type=GQL_CONNECTION_ACK)
9190
except Exception as e:
92-
await self.send_error(connection_context, op_id, e, GQL_CONNECTION_ERROR)
91+
await self.send_error(
92+
connection_context, op_id, e, GQL_CONNECTION_ERROR)
9393
await connection_context.close(1011)
9494

9595
async def on_start(self, connection_context, op_id, params):
@@ -100,14 +100,16 @@ async def on_start(self, connection_context, op_id, params):
100100
execution_result = await execution_result
101101

102102
if not hasattr(execution_result, '__aiter__'):
103-
await self.send_execution_result(connection_context, op_id, execution_result)
103+
await self.send_execution_result(
104+
connection_context, op_id, execution_result)
104105
else:
105106
iterator = await execution_result.__aiter__()
106107
connection_context.register_operation(op_id, iterator)
107108
async for single_result in iterator:
108109
if not connection_context.has_operation(op_id):
109110
break
110-
await self.send_execution_result(connection_context, op_id, single_result)
111+
await self.send_execution_result(
112+
connection_context, op_id, single_result)
111113
await self.send_message(connection_context, op_id, GQL_COMPLETE)
112114

113115
async def on_stop(self, connection_context, op_id):

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ universal = 1
1616

1717
[flake8]
1818
exclude = docs
19+
max-line-length = 88
1920

2021
[aliases]
2122
test = pytest

0 commit comments

Comments
 (0)