summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/state.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqlalchemy/orm/state.py')
-rw-r--r--lib/sqlalchemy/orm/state.py52
1 files changed, 27 insertions, 25 deletions
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 573e6515d..a9024b468 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -17,9 +17,10 @@ from .. import util
from . import exc as orm_exc, interfaces
from .path_registry import PathRegistry
from .base import PASSIVE_NO_RESULT, SQL_OK, NEVER_SET, ATTR_WAS_SET, \
- NO_VALUE, PASSIVE_NO_INITIALIZE, INIT_OK, PASSIVE_OFF
+ NO_VALUE, PASSIVE_NO_INITIALIZE, INIT_OK, PASSIVE_OFF
from . import base
+
class InstanceState(interfaces._InspectionAttr):
"""tracks state information at the instance level.
@@ -276,8 +277,8 @@ class InstanceState(interfaces._InspectionAttr):
state_dict = {'instance': self.obj()}
state_dict.update(
(k, self.__dict__[k]) for k in (
- 'committed_state', '_pending_mutations', 'modified', 'expired',
- 'callables', 'key', 'parents', 'load_options',
+ 'committed_state', '_pending_mutations', 'modified',
+ 'expired', 'callables', 'key', 'parents', 'load_options',
'class_',
) if k in self.__dict__
)
@@ -315,7 +316,7 @@ class InstanceState(interfaces._InspectionAttr):
if 'load_path' in state_dict:
self.load_path = PathRegistry.\
- deserialize(state_dict['load_path'])
+ deserialize(state_dict['load_path'])
state_dict['manager'](self, inst, state_dict)
@@ -418,7 +419,7 @@ class InstanceState(interfaces._InspectionAttr):
return PASSIVE_NO_RESULT
toload = self.expired_attributes.\
- intersection(self.unmodified)
+ intersection(self.unmodified)
self.manager.deferred_scalar_loader(self, toload)
@@ -441,7 +442,7 @@ class InstanceState(interfaces._InspectionAttr):
"""Return self.unmodified.intersection(keys)."""
return set(keys).intersection(self.manager).\
- difference(self.committed_state)
+ difference(self.committed_state)
@property
def unloaded(self):
@@ -452,15 +453,15 @@ class InstanceState(interfaces._InspectionAttr):
"""
return set(self.manager).\
- difference(self.committed_state).\
- difference(self.dict)
+ difference(self.committed_state).\
+ difference(self.dict)
@property
def _unloaded_non_object(self):
return self.unloaded.intersection(
- attr for attr in self.manager
- if self.manager[attr].impl.accepts_scalar_loader
- )
+ attr for attr in self.manager
+ if self.manager[attr].impl.accepts_scalar_loader
+ )
@property
def expired_attributes(self):
@@ -477,7 +478,8 @@ class InstanceState(interfaces._InspectionAttr):
def _instance_dict(self):
return None
- def _modified_event(self, dict_, attr, previous, collection=False, force=False):
+ def _modified_event(
+ self, dict_, attr, previous, collection=False, force=False):
if not attr.send_modified_events:
return
if attr.key not in self.committed_state or force:
@@ -508,13 +510,13 @@ class InstanceState(interfaces._InspectionAttr):
if inst is None:
raise orm_exc.ObjectDereferencedError(
- "Can't emit change event for attribute '%s' - "
- "parent object of type %s has been garbage "
- "collected."
- % (
- self.manager[attr.key],
- base.state_class_str(self)
- ))
+ "Can't emit change event for attribute '%s' - "
+ "parent object of type %s has been garbage "
+ "collected."
+ % (
+ self.manager[attr.key],
+ base.state_class_str(self)
+ ))
self.modified = True
def _commit(self, dict_, keys):
@@ -533,8 +535,8 @@ class InstanceState(interfaces._InspectionAttr):
self.expired = False
for key in set(self.callables).\
- intersection(keys).\
- intersection(dict_):
+ intersection(keys).\
+ intersection(dict_):
del self.callables[key]
def _commit_all(self, dict_, instance_dict=None):
@@ -617,7 +619,7 @@ class AttributeState(object):
"""
return self.state.manager[self.key].__get__(
- self.state.obj(), self.state.class_)
+ self.state.obj(), self.state.class_)
@property
def history(self):
@@ -636,7 +638,7 @@ class AttributeState(object):
"""
return self.state.get_history(self.key,
- PASSIVE_NO_INITIALIZE)
+ PASSIVE_NO_INITIALIZE)
def load_history(self):
"""Return the current pre-flush change history for
@@ -655,8 +657,7 @@ class AttributeState(object):
"""
return self.state.get_history(self.key,
- PASSIVE_OFF ^ INIT_OK)
-
+ PASSIVE_OFF ^ INIT_OK)
class PendingCollection(object):
@@ -667,6 +668,7 @@ class PendingCollection(object):
PendingCollection are applied to it to produce the final result.
"""
+
def __init__(self):
self.deleted_items = util.IdentitySet()
self.added_items = util.OrderedIdentitySet()