Skip to content

Commit 54ef52e

Browse files
committed
Reformatted files using black
1 parent 96789b2 commit 54ef52e

Some content is hidden

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

41 files changed

+1468
-1529
lines changed

graphene_django/__init__.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
from .types import (
2-
DjangoObjectType,
3-
)
4-
from .fields import (
5-
DjangoConnectionField,
6-
)
1+
from .types import DjangoObjectType
2+
from .fields import DjangoConnectionField
73

8-
__version__ = '2.1rc1'
4+
__version__ = "2.1rc1"
95

10-
__all__ = [
11-
'__version__',
12-
'DjangoObjectType',
13-
'DjangoConnectionField'
14-
]
6+
__all__ = ["__version__", "DjangoObjectType", "DjangoConnectionField"]

graphene_django/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class MissingType(object):
77
# and we cannot have psycopg2 on PyPy
88
from django.contrib.postgres.fields import ArrayField, HStoreField, RangeField
99
except ImportError:
10-
ArrayField, HStoreField, JSONField, RangeField = (MissingType, ) * 4
10+
ArrayField, HStoreField, JSONField, RangeField = (MissingType,) * 4
1111

1212

1313
try:

graphene_django/converter.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
from django.db import models
22
from django.utils.encoding import force_text
33

4-
from graphene import (ID, Boolean, Dynamic, Enum, Field, Float, Int, List,
5-
NonNull, String, UUID, DateTime, Date, Time)
4+
from graphene import (
5+
ID,
6+
Boolean,
7+
Dynamic,
8+
Enum,
9+
Field,
10+
Float,
11+
Int,
12+
List,
13+
NonNull,
14+
String,
15+
UUID,
16+
DateTime,
17+
Date,
18+
Time,
19+
)
620
from graphene.types.json import JSONString
721
from graphene.utils.str_converters import to_camel_case, to_const
822
from graphql import assert_valid_name
@@ -32,7 +46,7 @@ def get_choices(choices):
3246
else:
3347
name = convert_choice_name(value)
3448
while name in converted_names:
35-
name += '_' + str(len(converted_names))
49+
name += "_" + str(len(converted_names))
3650
converted_names.append(name)
3751
description = help_text
3852
yield name, value, description
@@ -43,16 +57,15 @@ def convert_django_field_with_choices(field, registry=None):
4357
converted = registry.get_converted_field(field)
4458
if converted:
4559
return converted
46-
choices = getattr(field, 'choices', None)
60+
choices = getattr(field, "choices", None)
4761
if choices:
4862
meta = field.model._meta
49-
name = to_camel_case('{}_{}'.format(meta.object_name, field.name))
63+
name = to_camel_case("{}_{}".format(meta.object_name, field.name))
5064
choices = list(get_choices(choices))
5165
named_choices = [(c[0], c[1]) for c in choices]
5266
named_choices_descriptions = {c[0]: c[2] for c in choices}
5367

5468
class EnumWithDescriptionsType(object):
55-
5669
@property
5770
def description(self):
5871
return named_choices_descriptions[self.name]
@@ -69,8 +82,8 @@ def description(self):
6982
@singledispatch
7083
def convert_django_field(field, registry=None):
7184
raise Exception(
72-
"Don't know how to convert the Django field %s (%s)" %
73-
(field, field.__class__))
85+
"Don't know how to convert the Django field %s (%s)" % (field, field.__class__)
86+
)
7487

7588

7689
@convert_django_field.register(models.CharField)
@@ -147,7 +160,7 @@ def dynamic_type():
147160

148161
# We do this for a bug in Django 1.8, where null attr
149162
# is not available in the OneToOneRel instance
150-
null = getattr(field, 'null', True)
163+
null = getattr(field, "null", True)
151164
return Field(_type, required=not null)
152165

153166
return Dynamic(dynamic_type)
@@ -171,6 +184,7 @@ def dynamic_type():
171184
# defined filter_fields in the DjangoObjectType Meta
172185
if _type._meta.filter_fields:
173186
from .filter.fields import DjangoFilterConnectionField
187+
174188
return DjangoFilterConnectionField(_type)
175189

176190
return DjangoConnectionField(_type)

graphene_django/debug/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .middleware import DjangoDebugMiddleware
22
from .types import DjangoDebug
33

4-
__all__ = ['DjangoDebugMiddleware', 'DjangoDebug']
4+
__all__ = ["DjangoDebugMiddleware", "DjangoDebug"]

graphene_django/debug/middleware.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class DjangoDebugContext(object):
10-
1110
def __init__(self):
1211
self.debug_promise = None
1312
self.promises = []
@@ -38,20 +37,21 @@ def disable_instrumentation(self):
3837

3938

4039
class DjangoDebugMiddleware(object):
41-
4240
def resolve(self, next, root, info, **args):
4341
context = info.context
44-
django_debug = getattr(context, 'django_debug', None)
42+
django_debug = getattr(context, "django_debug", None)
4543
if not django_debug:
4644
if context is None:
47-
raise Exception('DjangoDebug cannot be executed in None contexts')
45+
raise Exception("DjangoDebug cannot be executed in None contexts")
4846
try:
4947
context.django_debug = DjangoDebugContext()
5048
except Exception:
51-
raise Exception('DjangoDebug need the context to be writable, context received: {}.'.format(
52-
context.__class__.__name__
53-
))
54-
if info.schema.get_type('DjangoDebug') == info.return_type:
49+
raise Exception(
50+
"DjangoDebug need the context to be writable, context received: {}.".format(
51+
context.__class__.__name__
52+
)
53+
)
54+
if info.schema.get_type("DjangoDebug") == info.return_type:
5555
return context.django_debug.get_debug_promise()
5656
promise = next(root, info, **args)
5757
context.django_debug.add_promise(promise)

graphene_django/debug/sql/tracking.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class SQLQueryTriggered(Exception):
1616

1717

1818
class ThreadLocalState(local):
19-
2019
def __init__(self):
2120
self.enabled = True
2221

@@ -35,7 +34,7 @@ def recording(self, v):
3534

3635

3736
def wrap_cursor(connection, panel):
38-
if not hasattr(connection, '_graphene_cursor'):
37+
if not hasattr(connection, "_graphene_cursor"):
3938
connection._graphene_cursor = connection.cursor
4039

4140
def cursor():
@@ -46,7 +45,7 @@ def cursor():
4645

4746

4847
def unwrap_cursor(connection):
49-
if hasattr(connection, '_graphene_cursor'):
48+
if hasattr(connection, "_graphene_cursor"):
5049
previous_cursor = connection._graphene_cursor
5150
connection.cursor = previous_cursor
5251
del connection._graphene_cursor
@@ -87,61 +86,63 @@ def _quote_params(self, params):
8786
if not params:
8887
return params
8988
if isinstance(params, dict):
90-
return dict((key, self._quote_expr(value))
91-
for key, value in params.items())
89+
return dict((key, self._quote_expr(value)) for key, value in params.items())
9290
return list(map(self._quote_expr, params))
9391

9492
def _decode(self, param):
9593
try:
9694
return force_text(param, strings_only=True)
9795
except UnicodeDecodeError:
98-
return '(encoded string)'
96+
return "(encoded string)"
9997

10098
def _record(self, method, sql, params):
10199
start_time = time()
102100
try:
103101
return method(sql, params)
104102
finally:
105103
stop_time = time()
106-
duration = (stop_time - start_time)
107-
_params = ''
104+
duration = stop_time - start_time
105+
_params = ""
108106
try:
109107
_params = json.dumps(list(map(self._decode, params)))
110108
except Exception:
111109
pass # object not JSON serializable
112110

113-
alias = getattr(self.db, 'alias', 'default')
111+
alias = getattr(self.db, "alias", "default")
114112
conn = self.db.connection
115-
vendor = getattr(conn, 'vendor', 'unknown')
113+
vendor = getattr(conn, "vendor", "unknown")
116114

117115
params = {
118-
'vendor': vendor,
119-
'alias': alias,
120-
'sql': self.db.ops.last_executed_query(
121-
self.cursor, sql, self._quote_params(params)),
122-
'duration': duration,
123-
'raw_sql': sql,
124-
'params': _params,
125-
'start_time': start_time,
126-
'stop_time': stop_time,
127-
'is_slow': duration > 10,
128-
'is_select': sql.lower().strip().startswith('select'),
116+
"vendor": vendor,
117+
"alias": alias,
118+
"sql": self.db.ops.last_executed_query(
119+
self.cursor, sql, self._quote_params(params)
120+
),
121+
"duration": duration,
122+
"raw_sql": sql,
123+
"params": _params,
124+
"start_time": start_time,
125+
"stop_time": stop_time,
126+
"is_slow": duration > 10,
127+
"is_select": sql.lower().strip().startswith("select"),
129128
}
130129

131-
if vendor == 'postgresql':
130+
if vendor == "postgresql":
132131
# If an erroneous query was ran on the connection, it might
133132
# be in a state where checking isolation_level raises an
134133
# exception.
135134
try:
136135
iso_level = conn.isolation_level
137136
except conn.InternalError:
138-
iso_level = 'unknown'
139-
params.update({
140-
'trans_id': self.logger.get_transaction_id(alias),
141-
'trans_status': conn.get_transaction_status(),
142-
'iso_level': iso_level,
143-
'encoding': conn.encoding,
144-
})
137+
iso_level = "unknown"
138+
params.update(
139+
{
140+
"trans_id": self.logger.get_transaction_id(alias),
141+
"trans_status": conn.get_transaction_status(),
142+
"iso_level": iso_level,
143+
"encoding": conn.encoding,
144+
}
145+
)
145146

146147
_sql = DjangoDebugSQL(**params)
147148
# We keep `sql` to maintain backwards compatibility

0 commit comments

Comments
 (0)