try:
return getattr(self.comparator, key)
except AttributeError:
- raise AttributeError('Neither %r object nor %r object has an attribute %r' % (
+ raise AttributeError(
+ 'Neither %r object nor %r object has an attribute %r' % (
type(self).__name__,
type(self.comparator).__name__,
key)
try:
return getattr(self._comparator, attribute)
except AttributeError:
- raise AttributeError('Neither %r object nor %r object has an attribute %r' % (
+ raise AttributeError(
+ 'Neither %r object nor %r object has an attribute %r' % (
type(descriptor).__name__,
type(self._comparator).__name__,
attribute)
def __init__(self, class_, key,
callable_, trackparent=False, extension=None,
- compare_function=None, active_history=False, parent_token=None,
- expire_missing=True,
+ compare_function=None, active_history=False,
+ parent_token=None, expire_missing=True,
**kwargs):
"""Construct an AttributeImpl.
self.expire_missing = expire_missing
def hasparent(self, state, optimistic=False):
- """Return the boolean value of a `hasparent` flag attached to the given item.
+ """Return the boolean value of a `hasparent` flag attached to
+ the given state.
The `optimistic` flag determines what the default return value
should be if no `hasparent` flag can be located.
``InstrumentedAttribute`` constructor.
"""
- if callable_ is None:
- self.initialize(state)
- else:
- state.callables[self.key] = callable_
+ state.callables[self.key] = callable_
def get_history(self, state, dict_, passive=PASSIVE_OFF):
raise NotImplementedError()
return None
def initialize(self, state, dict_):
- """Initialize this attribute on the given object instance with an empty value."""
+ """Initialize the given state's attribute with an empty value."""
dict_[self.key] = None
return None
def __init__(self, class_, key, callable_,
class_manager, copy_function=None,
compare_function=None, **kwargs):
- super(ScalarAttributeImpl, self).__init__(class_, key, callable_,
- compare_function=compare_function, **kwargs)
+ super(ScalarAttributeImpl, self).__init__(
+ class_,
+ key,
+ callable_,
+ compare_function=compare_function,
+ **kwargs)
class_manager.mutable_attributes.add(key)
if copy_function is None:
- raise sa_exc.ArgumentError("MutableScalarAttributeImpl requires a copy function")
+ raise sa_exc.ArgumentError(
+ "MutableScalarAttributeImpl requires a copy function")
self.copy = copy_function
def get_history(self, state, dict_, passive=PASSIVE_OFF):
self, state, v)
def check_mutable_modified(self, state, dict_):
- (added, unchanged, deleted) = self.get_history(state, dict_, passive=PASSIVE_NO_INITIALIZE)
+ added, \
+ unchanged, \
+ deleted = self.get_history(state, dict_, passive=PASSIVE_NO_INITIALIZE)
return bool(added or deleted)
def get(self, state, dict_, passive=PASSIVE_OFF):
class ScalarObjectAttributeImpl(ScalarAttributeImpl):
- """represents a scalar-holding InstrumentedAttribute, where the target object is also instrumented.
+ """represents a scalar-holding InstrumentedAttribute,
+ where the target object is also instrumented.
- Adds events to delete/set operations.
+ Adds events to delete/set operations.
+
"""
accepts_scalar_loader = False
def __init__(self, class_, key, callable_,
trackparent=False, extension=None, copy_function=None,
compare_function=None, **kwargs):
- super(ScalarObjectAttributeImpl, self).__init__(class_, key,
- callable_, trackparent=trackparent, extension=extension,
- compare_function=compare_function, **kwargs)
+ super(ScalarObjectAttributeImpl, self).__init__(
+ class_,
+ key,
+ callable_,
+ trackparent=trackparent,
+ extension=extension,
+ compare_function=compare_function,
+ **kwargs)
if compare_function is None:
self.is_equal = identity_equal
def __init__(self, class_, key, callable_,
typecallable=None, trackparent=False, extension=None,
copy_function=None, compare_function=None, **kwargs):
- super(CollectionAttributeImpl, self).__init__(class_, key, callable_, trackparent=trackparent,
- extension=extension, compare_function=compare_function, **kwargs)
+ super(CollectionAttributeImpl, self).__init__(
+ class_,
+ key,
+ callable_,
+ trackparent=trackparent,
+ extension=extension,
+ compare_function=compare_function,
+ **kwargs)
if copy_function is None:
copy_function = self.__copy
self.copy = copy_function
-
self.collection_factory = typecallable
- # may be removed in 0.5:
- self.collection_interface = \
- util.duck_type_collection(self.collection_factory())
def __copy(self, item):
return [y for y in list(collections.collection_adapter(item))]
def set(self, state, child, oldchild, initiator):
if oldchild is child:
return child
+
if oldchild is not None and oldchild is not PASSIVE_NO_RESULT:
# With lazy=None, there's no guarantee that the full collection is
# present when updating via a backref.
old_state, old_dict = instance_state(oldchild), instance_dict(oldchild)
impl = old_state.get_impl(self.key)
try:
- impl.remove(old_state, old_dict, state.obj(), initiator, passive=PASSIVE_NO_FETCH)
+ impl.remove(old_state,
+ old_dict,
+ state.obj(),
+ initiator, passive=PASSIVE_NO_FETCH)
except (ValueError, KeyError, IndexError):
pass
+
if child is not None:
- new_state, new_dict = instance_state(child), instance_dict(child)
- new_state.get_impl(self.key).append(new_state, new_dict, state.obj(), initiator, passive=PASSIVE_NO_FETCH)
+ child_state, child_dict = instance_state(child), instance_dict(child)
+ child_state.get_impl(self.key).append(
+ child_state,
+ child_dict,
+ state.obj(),
+ initiator, passive=PASSIVE_NO_FETCH)
return child
def append(self, state, child, initiator):
child_state, child_dict = instance_state(child), instance_dict(child)
- child_state.get_impl(self.key).append(child_state, child_dict, state.obj(), initiator, passive=PASSIVE_NO_FETCH)
+ child_state.get_impl(self.key).append(
+ child_state,
+ child_dict,
+ state.obj(),
+ initiator, passive=PASSIVE_NO_FETCH)
return child
def remove(self, state, child, initiator):
if child is not None:
child_state, child_dict = instance_state(child), instance_dict(child)
- child_state.get_impl(self.key).remove(child_state, child_dict, state.obj(), initiator, passive=PASSIVE_NO_FETCH)
+ child_state.get_impl(self.key).remove(
+ child_state,
+ child_dict,
+ state.obj(),
+ initiator, passive=PASSIVE_NO_FETCH)
class Events(object):
HISTORY_BLANK = History(None, None, None)
-def _conditional_instance_state(obj):
- if not isinstance(obj, state.InstanceState):
- obj = instance_state(obj)
- else:
- util.warn_deprecated("Passing an InstanceState to get_history() or init_collection() is deprecated.")
- return obj
-
def get_history(obj, key, **kwargs):
"""Return a History record for the given object and attribute key.
this usage is deprecated.
"""
- return get_state_history(_conditional_instance_state(obj), key, **kwargs)
+ return get_state_history(instance_state(obj), key, **kwargs)
def get_state_history(state, key, **kwargs):
return state.get_history(key, **kwargs)
this usage is deprecated.
"""
- state = _conditional_instance_state(obj)
+ state = instance_state(obj)
dict_ = state.dict
return init_state_collection(state, dict_, key)