summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/event/base.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/event/base.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/event/base.py')
-rw-r--r--lib/sqlalchemy/event/base.py45
1 files changed, 26 insertions, 19 deletions
diff --git a/lib/sqlalchemy/event/base.py b/lib/sqlalchemy/event/base.py
index 137aec258..c750be70a 100644
--- a/lib/sqlalchemy/event/base.py
+++ b/lib/sqlalchemy/event/base.py
@@ -26,7 +26,7 @@ _registrars = util.defaultdict(list)
def _is_event_name(name):
- return not name.startswith('_') and name != 'dispatch'
+ return not name.startswith("_") and name != "dispatch"
class _UnpickleDispatch(object):
@@ -37,8 +37,8 @@ class _UnpickleDispatch(object):
def __call__(self, _instance_cls):
for cls in _instance_cls.__mro__:
- if 'dispatch' in cls.__dict__:
- return cls.__dict__['dispatch'].dispatch._for_class(
+ if "dispatch" in cls.__dict__:
+ return cls.__dict__["dispatch"].dispatch._for_class(
_instance_cls
)
else:
@@ -67,7 +67,7 @@ class _Dispatch(object):
# In one ORM edge case, an attribute is added to _Dispatch,
# so __dict__ is used in just that case and potentially others.
- __slots__ = '_parent', '_instance_cls', '__dict__', '_empty_listeners'
+ __slots__ = "_parent", "_instance_cls", "__dict__", "_empty_listeners"
_empty_listener_reg = weakref.WeakKeyDictionary()
@@ -79,7 +79,9 @@ class _Dispatch(object):
try:
self._empty_listeners = self._empty_listener_reg[instance_cls]
except KeyError:
- self._empty_listeners = self._empty_listener_reg[instance_cls] = {
+ self._empty_listeners = self._empty_listener_reg[
+ instance_cls
+ ] = {
ls.name: _EmptyListener(ls, instance_cls)
for ls in parent._event_descriptors
}
@@ -122,17 +124,18 @@ class _Dispatch(object):
:class:`._Dispatch` objects.
"""
- if '_joined_dispatch_cls' not in self.__class__.__dict__:
+ if "_joined_dispatch_cls" not in self.__class__.__dict__:
cls = type(
"Joined%s" % self.__class__.__name__,
- (_JoinedDispatcher, ), {'__slots__': self._event_names}
+ (_JoinedDispatcher,),
+ {"__slots__": self._event_names},
)
self.__class__._joined_dispatch_cls = cls
return self._joined_dispatch_cls(self, other)
def __reduce__(self):
- return _UnpickleDispatch(), (self._instance_cls, )
+ return _UnpickleDispatch(), (self._instance_cls,)
def _update(self, other, only_propagate=True):
"""Populate from the listeners in another :class:`_Dispatch`
@@ -140,8 +143,9 @@ class _Dispatch(object):
for ls in other._event_descriptors:
if isinstance(ls, _EmptyListener):
continue
- getattr(self, ls.name).\
- for_modify(self)._update(ls, only_propagate=only_propagate)
+ getattr(self, ls.name).for_modify(self)._update(
+ ls, only_propagate=only_propagate
+ )
def _clear(self):
for ls in self._event_descriptors:
@@ -164,14 +168,15 @@ def _create_dispatcher_class(cls, classname, bases, dict_):
# there's all kinds of ways to do this,
# i.e. make a Dispatch class that shares the '_listen' method
# of the Event class, this is the straight monkeypatch.
- if hasattr(cls, 'dispatch'):
+ if hasattr(cls, "dispatch"):
dispatch_base = cls.dispatch.__class__
else:
dispatch_base = _Dispatch
event_names = [k for k in dict_ if _is_event_name(k)]
- dispatch_cls = type("%sDispatch" % classname,
- (dispatch_base, ), {'__slots__': event_names})
+ dispatch_cls = type(
+ "%sDispatch" % classname, (dispatch_base,), {"__slots__": event_names}
+ )
dispatch_cls._event_names = event_names
@@ -186,7 +191,7 @@ def _create_dispatcher_class(cls, classname, bases, dict_):
setattr(dispatch_inst, ls.name, ls)
dispatch_cls._event_names.append(ls.name)
- if getattr(cls, '_dispatch_target', None):
+ if getattr(cls, "_dispatch_target", None):
cls._dispatch_target.dispatch = dispatcher(cls)
@@ -221,12 +226,14 @@ class Events(util.with_metaclass(_EventMeta, object)):
# Mapper, ClassManager, Session override this to
# also accept classes, scoped_sessions, sessionmakers, etc.
- if hasattr(target, 'dispatch'):
+ if hasattr(target, "dispatch"):
if (
dispatch_is(cls.dispatch.__class__)
or dispatch_is(type, cls.dispatch.__class__)
- or (dispatch_is(_JoinedDispatcher)
- and dispatch_parent_is(cls.dispatch.__class__))
+ or (
+ dispatch_is(_JoinedDispatcher)
+ and dispatch_parent_is(cls.dispatch.__class__)
+ )
):
return target
@@ -246,7 +253,7 @@ class Events(util.with_metaclass(_EventMeta, object)):
class _JoinedDispatcher(object):
"""Represent a connection between two _Dispatch objects."""
- __slots__ = 'local', 'parent', '_instance_cls'
+ __slots__ = "local", "parent", "_instance_cls"
def __init__(self, local, parent):
self.local = local
@@ -281,5 +288,5 @@ class dispatcher(object):
def __get__(self, obj, cls):
if obj is None:
return self.dispatch
- obj.__dict__['dispatch'] = disp = self.dispatch._for_instance(obj)
+ obj.__dict__["dispatch"] = disp = self.dispatch._for_instance(obj)
return disp