Skip to content

Commit ef1d982

Browse files
committed
black code
1 parent e77b19e commit ef1d982

30 files changed

+1100
-994
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,5 @@
7575
"python": ("https://docs.python.org/3", None),
7676
}
7777

78-
locale_dirs = ['locale/'] # path is example but recommended.
79-
gettext_compact = False # optional.
78+
locale_dirs = ["locale/"] # path is example but recommended.
79+
gettext_compact = False # optional.

src/gino/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
def create_engine(*args, **kwargs):
88
from sqlalchemy import create_engine
99

10-
kwargs.setdefault('strategy', 'gino')
10+
kwargs.setdefault("strategy", "gino")
1111
return create_engine(*args, **kwargs)
1212

1313

14-
__version__ = '0.8.5'
14+
__version__ = "0.8.5"

src/gino/api.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ class GinoExecutor:
4545
:meth:`db.scalar() <.Gino.scalar>` in this case.
4646
4747
"""
48-
__slots__ = ('_query',)
48+
49+
__slots__ = ("_query",)
4950

5051
def __init__(self, query):
5152
self._query = query
@@ -133,8 +134,7 @@ async def first(self, *multiparams, **params):
133134
(:class:`Gino`) is bound, while metadata is found in this query.
134135
135136
"""
136-
return await self._query.bind.first(self._query, *multiparams,
137-
**params)
137+
return await self._query.bind.first(self._query, *multiparams, **params)
138138

139139
async def one_or_none(self, *multiparams, **params):
140140
"""
@@ -145,8 +145,7 @@ async def one_or_none(self, *multiparams, **params):
145145
query.
146146
147147
"""
148-
return await self._query.bind.one_or_none(self._query, *multiparams,
149-
**params)
148+
return await self._query.bind.one_or_none(self._query, *multiparams, **params)
150149

151150
async def one(self, *multiparams, **params):
152151
"""
@@ -166,8 +165,7 @@ async def scalar(self, *multiparams, **params):
166165
(:class:`Gino`) is bound, while metadata is found in this query.
167166
168167
"""
169-
return await self._query.bind.scalar(self._query, *multiparams,
170-
**params)
168+
return await self._query.bind.scalar(self._query, *multiparams, **params)
171169

172170
async def status(self, *multiparams, **params):
173171
"""
@@ -177,8 +175,7 @@ async def status(self, *multiparams, **params):
177175
(:class:`Gino`) is bound, while metadata is found in this query.
178176
179177
"""
180-
return await self._query.bind.status(self._query, *multiparams,
181-
**params)
178+
return await self._query.bind.status(self._query, *multiparams, **params)
182179

183180
def iterate(self, *multiparams, **params):
184181
"""
@@ -190,8 +187,7 @@ def iterate(self, *multiparams, **params):
190187
"""
191188
connection = self._query.bind.current_connection
192189
if connection is None:
193-
raise ValueError(
194-
'No Connection in context, please provide one')
190+
raise ValueError("No Connection in context, please provide one")
195191
return connection.iterate(self._query, *multiparams, **params)
196192

197193

@@ -311,15 +307,22 @@ class Gino(sa.MetaData):
311307
312308
"""
313309

314-
no_delegate = {'create_engine', 'engine_from_config'}
310+
no_delegate = {"create_engine", "engine_from_config"}
315311
"""
316312
A set of symbols from :mod:`sqlalchemy` which is not delegated by
317313
:class:`Gino`.
318314
319315
"""
320316

321-
def __init__(self, bind=None, model_classes=None, query_ext=True,
322-
schema_ext=True, ext=True, **kwargs):
317+
def __init__(
318+
self,
319+
bind=None,
320+
model_classes=None,
321+
query_ext=True,
322+
schema_ext=True,
323+
ext=True,
324+
**kwargs
325+
):
323326
"""
324327
:param bind: A :class:`~.engine.GinoEngine` instance to bind. Also
325328
accepts string or :class:`~sqlalchemy.engine.url.URL`,
@@ -387,8 +390,7 @@ def bind(self):
387390
388391
"""
389392
if self._bind is None:
390-
return _PlaceHolder(
391-
UninitializedError('Gino engine is not initialized.'))
393+
return _PlaceHolder(UninitializedError("Gino engine is not initialized."))
392394
return self._bind
393395

394396
# noinspection PyMethodOverriding,PyAttributeOutsideInit
@@ -411,6 +413,7 @@ async def set_bind(self, bind, loop=None, **kwargs):
411413
bind = make_url(bind)
412414
if isinstance(bind, URL):
413415
from . import create_engine
416+
414417
bind = await create_engine(bind, loop=loop, **kwargs)
415418
self.bind = bind
416419
return bind
@@ -450,6 +453,7 @@ def __await__(self):
450453
async def init():
451454
await self.set_bind(self.bind)
452455
return self
456+
453457
return init().__await__()
454458

455459
def compile(self, elem, *multiparams, **params):
@@ -529,17 +533,17 @@ def transaction(self, *args, **kwargs):
529533

530534

531535
class _PlaceHolder:
532-
__slots__ = '_exception'
536+
__slots__ = "_exception"
533537

534538
def __init__(self, exception):
535539
self._exception = exception
536540

537541
def __getattribute__(self, item):
538-
if item == '_exception':
542+
if item == "_exception":
539543
return super().__getattribute__(item)
540544
raise self._exception
541545

542546
def __setattr__(self, key, value):
543-
if key == '_exception':
547+
if key == "_exception":
544548
return super().__setattr__(key, value)
545549
raise self._exception

src/gino/crud.py

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def select(*args):
3939
q = sa.select([getattr(owner, x) for x in args])
4040
if instance is not None:
4141
q = q.where(instance.lookup())
42-
return q.execution_options(model=weakref.ref(owner),
43-
return_model=False)
42+
return q.execution_options(model=weakref.ref(owner), return_model=False)
43+
4444
return select
4545

4646

@@ -79,7 +79,8 @@ class UpdateRequest:
7979
specific model instance and its database row.
8080
8181
"""
82-
def __init__(self, instance: 'CRUDModel'):
82+
83+
def __init__(self, instance: "CRUDModel"):
8384
self._instance = instance
8485
self._values = {}
8586
self._props = {}
@@ -116,8 +117,10 @@ async def apply(self, bind=None, timeout=DEFAULT):
116117
"""
117118
if self._locator is None:
118119
raise TypeError(
119-
'Model {} has no table, primary key or custom lookup()'.format(
120-
self._instance.__class__.__name__))
120+
"Model {} has no table, primary key or custom lookup()".format(
121+
self._instance.__class__.__name__
122+
)
123+
)
121124
cls = type(self._instance)
122125
values = self._values.copy()
123126

@@ -137,36 +140,38 @@ async def apply(self, bind=None, timeout=DEFAULT):
137140
for prop_name, updates in json_updates.items():
138141
prop = getattr(cls, prop_name)
139142
from .dialects.asyncpg import JSONB
143+
140144
if isinstance(prop.type, JSONB):
141145
if self._literal:
142146
values[prop_name] = prop.concat(updates)
143147
else:
144148
values[prop_name] = prop.concat(
145-
sa.func.jsonb_build_object(
146-
*itertools.chain(*updates.items())))
149+
sa.func.jsonb_build_object(*itertools.chain(*updates.items()))
150+
)
147151
else:
148-
raise TypeError('{} is not supported to update json '
149-
'properties in Gino. Please consider using '
150-
'JSONB.'.format(prop.type))
152+
raise TypeError(
153+
"{} is not supported to update json "
154+
"properties in Gino. Please consider using "
155+
"JSONB.".format(prop.type)
156+
)
151157

152158
opts = dict(return_model=False)
153159
if timeout is not DEFAULT:
154-
opts['timeout'] = timeout
155-
clause = type(self._instance).update.where(
156-
self._locator,
157-
).values(
158-
**self._instance._get_sa_values(values),
159-
).returning(
160-
*[getattr(cls, key) for key in values],
161-
).execution_options(**opts)
160+
opts["timeout"] = timeout
161+
clause = (
162+
type(self._instance)
163+
.update.where(self._locator,)
164+
.values(**self._instance._get_sa_values(values),)
165+
.returning(*[getattr(cls, key) for key in values],)
166+
.execution_options(**opts)
167+
)
162168
if bind is None:
163169
bind = cls.__metadata__.bind
164170
row = await bind.first(clause)
165171
if not row:
166172
raise NoSuchRowError()
167173
for k, v in row.items():
168-
self._instance.__values__[
169-
self._instance._column_name_map.invert_get(k)] = v
174+
self._instance.__values__[self._instance._column_name_map.invert_get(k)] = v
170175
for prop in self._props:
171176
prop.reload(self._instance)
172177
return self
@@ -208,11 +213,11 @@ def update(self, **values):
208213
for key, value in values.items():
209214
prop = cls.__dict__.get(key)
210215
if isinstance(prop, json_support.JSONProperty):
211-
value_from = '__profile__'
216+
value_from = "__profile__"
212217
method = self._set_prop
213218
k = prop
214219
else:
215-
value_from = '__values__'
220+
value_from = "__values__"
216221
method = self._set
217222
k = key
218223
if not isinstance(value, ClauseElement):
@@ -227,16 +232,19 @@ class Alias:
227232
Experimental proxy for table alias on model.
228233
229234
"""
235+
230236
def __init__(self, model, *args, **kwargs):
231237
# noinspection PyProtectedMember
232238
model._check_abstract()
233239
self.model = model
234240
self.alias = model.__table__.alias(*args, **kwargs)
235241

236242
def __getattr__(self, item):
237-
rv = getattr(self.alias.columns, item,
238-
getattr(self.alias, item,
239-
getattr(self.model, item, DEFAULT)))
243+
rv = getattr(
244+
self.alias.columns,
245+
item,
246+
getattr(self.alias, item, getattr(self.model, item, DEFAULT)),
247+
)
240248
if rv is DEFAULT:
241249
raise AttributeError
242250
return rv
@@ -429,16 +437,15 @@ def _init_table(cls, sub_cls):
429437
if isinstance(v, json_support.JSONProperty):
430438
if not hasattr(sub_cls, v.prop_name):
431439
raise AttributeError(
432-
'Requires "{}" JSON[B] column.'.format(
433-
v.prop_name))
440+
'Requires "{}" JSON[B] column.'.format(v.prop_name)
441+
)
434442
v.name = k
435443
if rv is not None:
436444
rv.__model__ = weakref.ref(sub_cls)
437445
return rv
438446

439447
@classmethod
440-
async def _create_without_instance(cls, bind=None, timeout=DEFAULT,
441-
**values):
448+
async def _create_without_instance(cls, bind=None, timeout=DEFAULT, **values):
442449
return await cls(**values)._create(bind=bind, timeout=timeout)
443450

444451
async def _create(self, bind=None, timeout=DEFAULT):
@@ -462,13 +469,14 @@ async def _create(self, bind=None, timeout=DEFAULT):
462469
# insert into database
463470
opts = dict(return_model=False, model=cls)
464471
if timeout is not DEFAULT:
465-
opts['timeout'] = timeout
472+
opts["timeout"] = timeout
466473
# noinspection PyArgumentList
467-
q = cls.__table__.insert().values(
468-
**self._get_sa_values(self.__values__)
469-
).returning(
470-
*cls
471-
).execution_options(**opts)
474+
q = (
475+
cls.__table__.insert()
476+
.values(**self._get_sa_values(self.__values__))
477+
.returning(*cls)
478+
.execution_options(**opts)
479+
)
472480
if bind is None:
473481
bind = cls.__metadata__.bind
474482
row = await bind.first(q)
@@ -517,9 +525,9 @@ async def get(cls, ident, bind=None, timeout=DEFAULT):
517525
columns = cls.__table__.primary_key.columns
518526
if len(ident_) != len(columns):
519527
raise ValueError(
520-
'Incorrect number of values as primary key: '
521-
'expected {}, got {}.'.format(
522-
len(columns), len(ident_)))
528+
"Incorrect number of values as primary key: "
529+
"expected {}, got {}.".format(len(columns), len(ident_))
530+
)
523531
clause = cls.query
524532
for i, c in enumerate(columns):
525533
try:
@@ -575,9 +583,11 @@ def lookup(self):
575583
if exps:
576584
return sa.and_(*exps)
577585
else:
578-
raise LookupError('Instance-level CRUD operations not allowed on '
579-
'models without primary keys or lookup(), please'
580-
' use model-level CRUD operations instead.')
586+
raise LookupError(
587+
"Instance-level CRUD operations not allowed on "
588+
"models without primary keys or lookup(), please"
589+
" use model-level CRUD operations instead."
590+
)
581591

582592
def _update(self, **values):
583593
return self._update_request_cls(self).update(**values)
@@ -758,10 +768,15 @@ class QueryModel(type):
758768
Metaclass of Model classes used for subqueries.
759769
760770
"""
771+
761772
def __getattr__(self, item):
762-
rv = getattr(self._query.columns, item,
763-
getattr(self._model.__table__.columns, item,
764-
getattr(self._model, item, DEFAULT)))
773+
rv = getattr(
774+
self._query.columns,
775+
item,
776+
getattr(
777+
self._model.__table__.columns, item, getattr(self._model, item, DEFAULT)
778+
),
779+
)
765780
# replace `cls` in classmethod in models to `self`
766781
if inspect.ismethod(rv) and inspect.isclass(rv.__self__):
767782
return lambda *args, **kwargs: rv.__func__(self, *args, **kwargs)

0 commit comments

Comments
 (0)