diff options
| author | Jason Kirtland <jek@discorporate.us> | 2008-07-15 20:20:41 +0000 |
|---|---|---|
| committer | Jason Kirtland <jek@discorporate.us> | 2008-07-15 20:20:41 +0000 |
| commit | 3da6297d78a699087e538bb8fc5a92039ff21f98 (patch) | |
| tree | f7c07e5df4102da34f0781179c5dc90b8e21458f /lib/sqlalchemy | |
| parent | 901d76beba05f0131602b747f2e656adc4451860 (diff) | |
| download | sqlalchemy-3da6297d78a699087e538bb8fc5a92039ff21f98.tar.gz | |
Whitespace tweaks suggested by pep8.py
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/collections.py | 54 |
1 files changed, 28 insertions, 26 deletions
diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py index d86814525..0efd1d867 100644 --- a/lib/sqlalchemy/orm/collections.py +++ b/lib/sqlalchemy/orm/collections.py @@ -28,11 +28,11 @@ and return values to events:: The second approach is a bundle of targeted decorators that wrap appropriate append and remove notifiers around the mutation methods present in the standard Python ``list``, ``set`` and ``dict`` interfaces. These could be -specified in terms of generic decorator recipes, but are instead hand-tooled for -increased efficiency. The targeted decorators occasionally implement -adapter-like behavior, such as mapping bulk-set methods (``extend``, ``update``, -``__setslice__``, etc.) into the series of atomic mutation events that the ORM -requires. +specified in terms of generic decorator recipes, but are instead hand-tooled +for increased efficiency. The targeted decorators occasionally implement +adapter-like behavior, such as mapping bulk-set methods (``extend``, +``update``, ``__setslice__``, etc.) into the series of atomic mutation events +that the ORM requires. The targeted decorators are used internally for automatic instrumentation of entity collection classes. Every collection class goes through a @@ -108,7 +108,6 @@ from sqlalchemy import schema import sqlalchemy.util as sautil - __all__ = ['collection', 'collection_adapter', 'mapped_collection', 'column_mapped_collection', 'attribute_mapped_collection'] @@ -364,9 +363,10 @@ class collection(object): def adds(cls, arg): """Mark the method as adding an entity to the collection. - Adds "add to collection" handling to the method. The decorator argument - indicates which method argument holds the SQLAlchemy-relevant value. - Arguments can be specified positionally (i.e. integer) or by name:: + Adds "add to collection" handling to the method. The decorator + argument indicates which method argument holds the SQLAlchemy-relevant + value. Arguments can be specified positionally (i.e. integer) or by + name:: @collection.adds(1) def push(self, item): ... @@ -529,7 +529,8 @@ class CollectionAdapter(object): "Incompatible collection type: %s is not %s-like" % ( given, wanted)) - # If the object is an adapted collection, return the (iterable) adapter. + # If the object is an adapted collection, return the (iterable) + # adapter. if getattr(obj, '_sa_adapter', None) is not None: return getattr(obj, '_sa_adapter') elif setting_type == dict: @@ -606,9 +607,9 @@ class CollectionAdapter(object): self.attr.fire_pre_remove_event(self.owner_state, initiator=initiator) def __getstate__(self): - return { 'key': self.attr.key, - 'owner_state': self.owner_state, - 'data': self.data } + return {'key': self.attr.key, + 'owner_state': self.owner_state, + 'data': self.data} def __setstate__(self, d): self.attr = getattr(d['owner_state'].obj().__class__, d['key']).impl @@ -641,7 +642,7 @@ def bulk_replace(values, existing_adapter, new_adapter): idset = sautil.IdentitySet constants = idset(existing_adapter or ()).intersection(values or ()) additions = idset(values or ()).difference(constants) - removals = idset(existing_adapter or ()).difference(constants) + removals = idset(existing_adapter or ()).difference(constants) for member in values or (): if member in additions: @@ -783,7 +784,8 @@ def _instrument_class(cls): # apply ABC auto-decoration to methods that need it for method, decorator in decorators.items(): fn = getattr(cls, method, None) - if fn and method not in methods and not hasattr(fn, '_sa_instrumented'): + if (fn and method not in methods and + not hasattr(fn, '_sa_instrumented')): setattr(cls, method, decorator(fn)) # ensure all roles are present, and apply implicit instrumentation if @@ -1110,7 +1112,8 @@ def _dict_decorators(): if __other is not Unspecified: if hasattr(__other, 'keys'): for key in __other.keys(): - if key not in self or self[key] is not __other[key]: + if (key not in self or + self[key] is not __other[key]): self[key] = __other[key] else: for key, value in __other: @@ -1127,7 +1130,6 @@ def _dict_decorators(): l.pop('Unspecified') return l - _set_binop_bases = (set, frozenset, sets.BaseSet) def _set_binops_check_strict(self, obj): @@ -1325,19 +1327,19 @@ __canned_instrumentation = { } __interfaces = { - list: { 'appender': 'append', - 'remover': 'remove', - 'iterator': '__iter__', - '_decorators': _list_decorators(), }, - set: { 'appender': 'add', + list: {'appender': 'append', 'remover': 'remove', 'iterator': '__iter__', - '_decorators': _set_decorators(), }, + '_decorators': _list_decorators(), }, + set: {'appender': 'add', + 'remover': 'remove', + 'iterator': '__iter__', + '_decorators': _set_decorators(), }, # decorators are required for dicts and object collections. - dict: { 'iterator': 'itervalues', - '_decorators': _dict_decorators(), }, + dict: {'iterator': 'itervalues', + '_decorators': _dict_decorators(), }, # < 0.4 compatible naming, deprecated- use decorators instead. - None: { } + None: {} } class MappedCollection(dict): |
