diff options
author | Brian Jarrett <celttechie@gmail.com> | 2014-07-20 12:44:40 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-20 12:44:40 -0400 |
commit | cca03097f47f22783d42d1853faac6cf84607c5a (patch) | |
tree | 4fe1a63d03a2d88d1cf37e1167759dfaf84f4ce7 /lib/sqlalchemy/orm/descriptor_props.py | |
parent | 827329a0cca5351094a1a86b6b2be2b9182f0ae2 (diff) | |
download | sqlalchemy-cca03097f47f22783d42d1853faac6cf84607c5a.tar.gz |
- apply pep8 formatting to sqlalchemy/sql, sqlalchemy/util, sqlalchemy/dialects,
sqlalchemy/orm, sqlalchemy/event, sqlalchemy/testing
Diffstat (limited to 'lib/sqlalchemy/orm/descriptor_props.py')
-rw-r--r-- | lib/sqlalchemy/orm/descriptor_props.py | 135 |
1 files changed, 68 insertions, 67 deletions
diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py index 4c335a71c..5ed24b8c0 100644 --- a/lib/sqlalchemy/orm/descriptor_props.py +++ b/lib/sqlalchemy/orm/descriptor_props.py @@ -39,7 +39,7 @@ class DescriptorProperty(MapperProperty): if hasattr(prop, 'get_history'): def get_history(self, state, dict_, - passive=attributes.PASSIVE_OFF): + passive=attributes.PASSIVE_OFF): return prop.get_history(state, dict_, passive) if self.descriptor is None: @@ -63,16 +63,15 @@ class DescriptorProperty(MapperProperty): fdel=fdel, ) - proxy_attr = attributes.\ - create_proxied_attribute(self.descriptor)\ - ( - self.parent.class_, - self.key, - self.descriptor, - lambda: self._comparator_factory(mapper), - doc=self.doc, - original_property=self - ) + proxy_attr = attributes.create_proxied_attribute( + self.descriptor)( + self.parent.class_, + self.key, + self.descriptor, + lambda: self._comparator_factory(mapper), + doc=self.doc, + original_property=self + ) proxy_attr.impl = _ProxyImpl(self.key) mapper.class_manager.instrument_attribute(self.key, proxy_attr) @@ -90,11 +89,12 @@ class CompositeProperty(DescriptorProperty): :ref:`mapper_composite` """ + def __init__(self, class_, *attrs, **kwargs): """Return a composite column-based property for use with a Mapper. - See the mapping documentation section :ref:`mapper_composite` for a full - usage example. + See the mapping documentation section :ref:`mapper_composite` for a + full usage example. The :class:`.MapperProperty` returned by :func:`.composite` is the :class:`.CompositeProperty`. @@ -118,13 +118,14 @@ class CompositeProperty(DescriptorProperty): A group name for this property when marked as deferred. :param deferred: - When True, the column property is "deferred", meaning that it does not - load immediately, and is instead loaded when the attribute is first - accessed on an instance. See also :func:`~sqlalchemy.orm.deferred`. + When True, the column property is "deferred", meaning that it does + not load immediately, and is instead loaded when the attribute is + first accessed on an instance. See also + :func:`~sqlalchemy.orm.deferred`. :param comparator_factory: a class which extends - :class:`.CompositeProperty.Comparator` which provides custom SQL clause - generation for comparison operations. + :class:`.CompositeProperty.Comparator` which provides custom SQL + clause generation for comparison operations. :param doc: optional string that will be applied as the doc on the @@ -138,8 +139,8 @@ class CompositeProperty(DescriptorProperty): :param extension: an :class:`.AttributeExtension` instance, or list of extensions, which will be prepended to the list of - attribute listeners for the resulting descriptor placed on the class. - **Deprecated.** Please see :class:`.AttributeEvents`. + attribute listeners for the resulting descriptor placed on the + class. **Deprecated.** Please see :class:`.AttributeEvents`. """ @@ -149,14 +150,13 @@ class CompositeProperty(DescriptorProperty): self.deferred = kwargs.get('deferred', False) self.group = kwargs.get('group', None) self.comparator_factory = kwargs.pop('comparator_factory', - self.__class__.Comparator) + self.__class__.Comparator) if 'info' in kwargs: self.info = kwargs.pop('info') util.set_creation_order(self) self._create_descriptor() - def instrument_class(self, mapper): super(CompositeProperty, self).instrument_class(mapper) self._setup_event_handlers() @@ -241,16 +241,17 @@ class CompositeProperty(DescriptorProperty): props = [] for attr in self.attrs: if isinstance(attr, str): - prop = self.parent.get_property(attr, _configure_mappers=False) + prop = self.parent.get_property( + attr, _configure_mappers=False) elif isinstance(attr, schema.Column): prop = self.parent._columntoproperty[attr] elif isinstance(attr, attributes.InstrumentedAttribute): prop = attr.property else: raise sa_exc.ArgumentError( - "Composite expects Column objects or mapped " - "attributes/attribute names as arguments, got: %r" - % (attr,)) + "Composite expects Column objects or mapped " + "attributes/attribute names as arguments, got: %r" + % (attr,)) props.append(prop) return props @@ -268,8 +269,8 @@ class CompositeProperty(DescriptorProperty): if self.deferred: prop.deferred = self.deferred prop.strategy_class = prop._strategy_lookup( - ("deferred", True), - ("instrument", True)) + ("deferred", True), + ("instrument", True)) prop.group = self.group def _setup_event_handlers(self): @@ -288,11 +289,11 @@ class CompositeProperty(DescriptorProperty): if k not in dict_: return - #assert self.key not in dict_ + # assert self.key not in dict_ dict_[self.key] = self.composite_class( - *[state.dict[key] for key in - self._attribute_keys] - ) + *[state.dict[key] for key in + self._attribute_keys] + ) def expire_handler(state, keys): if keys is None or set(self._attribute_keys).intersection(keys): @@ -309,15 +310,15 @@ class CompositeProperty(DescriptorProperty): state.dict.pop(self.key, None) event.listen(self.parent, 'after_insert', - insert_update_handler, raw=True) + insert_update_handler, raw=True) event.listen(self.parent, 'after_update', - insert_update_handler, raw=True) + insert_update_handler, raw=True) event.listen(self.parent, 'load', - load_handler, raw=True, propagate=True) + load_handler, raw=True, propagate=True) event.listen(self.parent, 'refresh', - load_handler, raw=True, propagate=True) + load_handler, raw=True, propagate=True) event.listen(self.parent, 'expire', - expire_handler, raw=True, propagate=True) + expire_handler, raw=True, propagate=True) # TODO: need a deserialize hook here @@ -368,14 +369,14 @@ class CompositeProperty(DescriptorProperty): def __init__(self, property, expr): self.property = property super(CompositeProperty.CompositeBundle, self).__init__( - property.key, *expr) + property.key, *expr) def create_row_processor(self, query, procs, labels): def proc(row, result): - return self.property.composite_class(*[proc(row, result) for proc in procs]) + return self.property.composite_class( + *[proc(row, result) for proc in procs]) return proc - class Comparator(PropComparator): """Produce boolean, comparison, and other operators for :class:`.CompositeProperty` attributes. @@ -395,7 +396,6 @@ class CompositeProperty(DescriptorProperty): """ - __hash__ = None @property @@ -403,20 +403,22 @@ class CompositeProperty(DescriptorProperty): return self.__clause_element__() def __clause_element__(self): - return expression.ClauseList(group=False, *self._comparable_elements) + return expression.ClauseList( + group=False, *self._comparable_elements) def _query_clause_element(self): - return CompositeProperty.CompositeBundle(self.prop, self.__clause_element__()) + return CompositeProperty.CompositeBundle( + self.prop, self.__clause_element__()) @util.memoized_property def _comparable_elements(self): if self._adapt_to_entity: return [ - getattr( - self._adapt_to_entity.entity, - prop.key - ) for prop in self.prop._comparable_elements - ] + getattr( + self._adapt_to_entity.entity, + prop.key + ) for prop in self.prop._comparable_elements + ] else: return self.prop._comparable_elements @@ -471,9 +473,9 @@ class ConcreteInheritedProperty(DescriptorProperty): def __init__(self): def warn(): raise AttributeError("Concrete %s does not implement " - "attribute %r at the instance level. Add this " - "property explicitly to %s." % - (self.parent, self.key, self.parent)) + "attribute %r at the instance level. Add " + "this property explicitly to %s." % + (self.parent, self.key, self.parent)) class NoninheritedConcreteProp(object): def __set__(s, obj, value): @@ -493,8 +495,8 @@ class ConcreteInheritedProperty(DescriptorProperty): class SynonymProperty(DescriptorProperty): def __init__(self, name, map_column=None, - descriptor=None, comparator_factory=None, - doc=None): + descriptor=None, comparator_factory=None, + doc=None): """Denote an attribute name as a synonym to a mapped property, in that the attribute will mirror the value and expression behavior of another attribute. @@ -523,11 +525,11 @@ class SynonymProperty(DescriptorProperty): job_status = synonym("_job_status", map_column=True) The above class ``MyClass`` will now have the ``job_status`` - :class:`.Column` object mapped to the attribute named ``_job_status``, - and the attribute named ``job_status`` will refer to the synonym - itself. This feature is typically used in conjunction with the - ``descriptor`` argument in order to link a user-defined descriptor - as a "wrapper" for an existing column. + :class:`.Column` object mapped to the attribute named + ``_job_status``, and the attribute named ``job_status`` will refer + to the synonym itself. This feature is typically used in + conjunction with the ``descriptor`` argument in order to link a + user-defined descriptor as a "wrapper" for an existing column. :param comparator_factory: A subclass of :class:`.PropComparator` that will provide custom comparison behavior at the SQL expression @@ -580,12 +582,12 @@ class SynonymProperty(DescriptorProperty): raise sa_exc.ArgumentError( "Can't compile synonym '%s': no column on table " "'%s' named '%s'" - % (self.name, parent.mapped_table.description, self.key)) + % (self.name, parent.mapped_table.description, self.key)) elif parent.mapped_table.c[self.key] in \ parent._columntoproperty and \ parent._columntoproperty[ - parent.mapped_table.c[self.key] - ].key == self.name: + parent.mapped_table.c[self.key] + ].key == self.name: raise sa_exc.ArgumentError( "Can't call map_column=True for synonym %r=%r, " "a ColumnProperty already exists keyed to the name " @@ -594,9 +596,9 @@ class SynonymProperty(DescriptorProperty): ) p = properties.ColumnProperty(parent.mapped_table.c[self.key]) parent._configure_property( - self.name, p, - init=init, - setparent=True) + self.name, p, + init=init, + setparent=True) p._mapped_by_synonym = self.key self.parent = parent @@ -646,7 +648,8 @@ class ComparableProperty(DescriptorProperty): id = Column(Integer, primary_key=True) word = Column(String) word_insensitive = comparable_property(lambda prop, mapper: - CaseInsensitiveComparator(mapper.c.word, mapper) + CaseInsensitiveComparator( + mapper.c.word, mapper) ) @@ -675,5 +678,3 @@ class ComparableProperty(DescriptorProperty): def _comparator_factory(self, mapper): return self.comparator_factory(self, mapper) - - |