summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/scoping.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 01:14:26 -0500
committermike bayer <mike_mp@zzzcomputing.com>2019-01-06 17:34:50 +0000
commit1e1a38e7801f410f244e4bbb44ec795ae152e04e (patch)
tree28e725c5c8188bd0cfd133d1e268dbca9b524978 /lib/sqlalchemy/orm/scoping.py
parent404e69426b05a82d905cbb3ad33adafccddb00dd (diff)
downloadsqlalchemy-1e1a38e7801f410f244e4bbb44ec795ae152e04e.tar.gz
Run black -l 79 against all source files
This is a straight reformat run using black as is, with no edits applied at all. The black run will format code consistently, however in some cases that are prevalent in SQLAlchemy code it produces too-long lines. The too-long lines will be resolved in the following commit that will resolve all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9
Diffstat (limited to 'lib/sqlalchemy/orm/scoping.py')
-rw-r--r--lib/sqlalchemy/orm/scoping.py38
1 files changed, 29 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py
index 2e16872f9..2eeaf5b6d 100644
--- a/lib/sqlalchemy/orm/scoping.py
+++ b/lib/sqlalchemy/orm/scoping.py
@@ -11,7 +11,7 @@ from . import class_mapper, exc as orm_exc
from .session import Session
-__all__ = ['scoped_session']
+__all__ = ["scoped_session"]
class scoped_session(object):
@@ -65,7 +65,8 @@ class scoped_session(object):
if self.registry.has():
raise sa_exc.InvalidRequestError(
"Scoped session is already present; "
- "no new arguments may be specified.")
+ "no new arguments may be specified."
+ )
else:
sess = self.session_factory(**kw)
self.registry.set(sess)
@@ -99,9 +100,11 @@ class scoped_session(object):
"""
if self.registry.has():
- warn('At least one scoped session is already present. '
- ' configure() can not affect sessions that have '
- 'already been created.')
+ warn(
+ "At least one scoped session is already present. "
+ " configure() can not affect sessions that have "
+ "already been created."
+ )
self.session_factory.configure(**kwargs)
@@ -129,6 +132,7 @@ class scoped_session(object):
a class.
"""
+
class query(object):
def __get__(s, instance, owner):
try:
@@ -142,8 +146,10 @@ class scoped_session(object):
return self.registry().query(mapper)
except orm_exc.UnmappedClassError:
return None
+
return query()
+
ScopedSession = scoped_session
"""Old name for backwards compatibility."""
@@ -151,8 +157,10 @@ ScopedSession = scoped_session
def instrument(name):
def do(self, *args, **kwargs):
return getattr(self.registry(), name)(*args, **kwargs)
+
return do
+
for meth in Session.public_methods:
setattr(scoped_session, meth, instrument(meth))
@@ -166,16 +174,28 @@ def makeprop(name):
return property(get, set)
-for prop in ('bind', 'dirty', 'deleted', 'new', 'identity_map',
- 'is_active', 'autoflush', 'no_autoflush', 'info',
- 'autocommit'):
+
+for prop in (
+ "bind",
+ "dirty",
+ "deleted",
+ "new",
+ "identity_map",
+ "is_active",
+ "autoflush",
+ "no_autoflush",
+ "info",
+ "autocommit",
+):
setattr(scoped_session, prop, makeprop(prop))
def clslevel(name):
def do(cls, *args, **kwargs):
return getattr(Session, name)(*args, **kwargs)
+
return classmethod(do)
-for prop in ('close_all', 'object_session', 'identity_key'):
+
+for prop in ("close_all", "object_session", "identity_key"):
setattr(scoped_session, prop, clslevel(prop))