[Sqlalchemy-commits] sqlalchemy: just a pep8 pass of lib/sqlalchemy/orm/
Brought to you by:
zzzeek
From: <co...@sq...> - 2012-11-19 22:19:49
|
details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/d0400a7fc12e changeset: 8941:d0400a7fc12e user: diana date: Mon Nov 19 17:19:24 2012 -0500 description: just a pep8 pass of lib/sqlalchemy/orm/ diffstat: lib/sqlalchemy/orm/identity.py | 20 ++- lib/sqlalchemy/orm/instrumentation.py | 7 +- lib/sqlalchemy/orm/interfaces.py | 41 ++++--- lib/sqlalchemy/orm/loading.py | 10 +- lib/sqlalchemy/orm/mapper.py | 14 +- lib/sqlalchemy/orm/persistence.py | 26 ++++- lib/sqlalchemy/orm/properties.py | 39 +++--- lib/sqlalchemy/orm/query.py | 171 ++++++++++++++++----------------- lib/sqlalchemy/orm/relationships.py | 85 ++++++++-------- lib/sqlalchemy/orm/scoping.py | 14 ++- 10 files changed, 238 insertions(+), 189 deletions(-) diffs (truncated from 1620 to 300 lines): diff -r 04d3ffa1e58a -r d0400a7fc12e lib/sqlalchemy/orm/identity.py --- a/lib/sqlalchemy/orm/identity.py Mon Nov 19 15:29:28 2012 -0500 +++ b/lib/sqlalchemy/orm/identity.py Mon Nov 19 17:19:24 2012 -0500 @@ -39,8 +39,10 @@ return self._modified def check_modified(self): - """return True if any InstanceStates present have been marked as 'modified'.""" + """return True if any InstanceStates present have been marked + as 'modified'. + """ return bool(self._modified) def has_key(self, key): @@ -64,6 +66,7 @@ def __delitem__(self, key): raise NotImplementedError("IdentityMap uses remove() to remove data") + class WeakInstanceDict(IdentityMap): def __init__(self): IdentityMap.__init__(self) @@ -110,9 +113,10 @@ if existing_state is not state: o = existing_state.obj() if o is not None: - raise AssertionError("A conflicting state is already " - "present in the identity map for key %r" - % (key, )) + raise AssertionError( + "A conflicting state is already " + "present in the identity map for key %r" + % (key, )) else: return except KeyError: @@ -156,10 +160,12 @@ # return iter(self._values()) # Py2K items = _items + def iteritems(self): return iter(self.items()) values = _values + def itervalues(self): return iter(self.values()) # end Py2K @@ -180,12 +186,15 @@ def prune(self): return 0 + class StrongInstanceDict(IdentityMap): def all_states(self): return [attributes.instance_state(o) for o in self.itervalues()] def contains_state(self, state): - return state.key in self and attributes.instance_state(self[state.key]) is state + return ( + state.key in self and + attributes.instance_state(self[state.key]) is state) def replace(self, state): if dict.__contains__(self, state.key): @@ -232,4 +241,3 @@ dict.update(self, keepers) self.modified = bool(dirty) return ref_count - len(self) - diff -r 04d3ffa1e58a -r d0400a7fc12e lib/sqlalchemy/orm/instrumentation.py --- a/lib/sqlalchemy/orm/instrumentation.py Mon Nov 19 15:29:28 2012 -0500 +++ b/lib/sqlalchemy/orm/instrumentation.py Mon Nov 19 17:19:24 2012 -0500 @@ -32,9 +32,9 @@ from . import exc, collections, events from operator import attrgetter from .. import event, util -import weakref state = util.importlater("sqlalchemy.orm", "state") + class ClassManager(dict): """tracks state information at the class level.""" @@ -308,6 +308,7 @@ return '<%s of %r at %x>' % ( self.__class__.__name__, self.class_, id(self)) + class InstrumentationFactory(object): """Factory for new ClassManager instances.""" @@ -352,6 +353,7 @@ # when importred. _instrumentation_factory = InstrumentationFactory() + def register_class(class_): """Register class instrumentation. @@ -364,6 +366,7 @@ manager = _instrumentation_factory.create_manager_for_cls(class_) return manager + def unregister_class(class_): """Unregister class instrumentation.""" @@ -390,6 +393,7 @@ manager_of_class = _default_manager_getter = ClassManager.manager_getter() + def _generate_init(class_, class_manager): """Build an __init__ decorator that triggers ClassManager events.""" @@ -433,4 +437,3 @@ #if func_kw_defaults: # __init__.__kwdefaults__ = func_kw_defaults return __init__ - diff -r 04d3ffa1e58a -r d0400a7fc12e lib/sqlalchemy/orm/interfaces.py --- a/lib/sqlalchemy/orm/interfaces.py Mon Nov 19 15:29:28 2012 -0500 +++ b/lib/sqlalchemy/orm/interfaces.py Mon Nov 19 17:19:24 2012 -0500 @@ -16,7 +16,6 @@ """ from __future__ import absolute_import -from itertools import chain from .. import exc as sa_exc, util, inspect from ..sql import operators @@ -53,6 +52,7 @@ SessionExtension, \ MapperExtension + class _InspectionAttr(object): """Define a series of attributes that all ORM inspection targets need to have.""" @@ -65,11 +65,14 @@ is_attribute = False is_clause_element = False + class _MappedAttribute(object): """Mixin for attributes which should be replaced by mapper-assigned attributes. """ + + class MapperProperty(_MappedAttribute, _InspectionAttr): """Manage the relationship of a ``Mapper`` to a single class attribute, as well as that attribute as it appears on individual @@ -80,7 +83,8 @@ mapped :class:`.Column`, which is represented in a mapping as an instance of :class:`.ColumnProperty`, and a reference to another class produced by :func:`.relationship`, - represented in the mapping as an instance of :class:`.RelationshipProperty`. + represented in the mapping as an instance of + :class:`.RelationshipProperty`. """ @@ -185,7 +189,6 @@ """ pass - def is_primary(self): """Return True if this ``MapperProperty``'s mapper is the primary mapper for its class. @@ -216,6 +219,7 @@ return operator(self.comparator, value) + class PropComparator(operators.ColumnOperators): """Defines boolean, comparison, and other operators for :class:`.MapperProperty` objects. @@ -223,8 +227,8 @@ SQLAlchemy allows for operators to be redefined at both the Core and ORM level. :class:`.PropComparator` is the base class of operator redefinition for ORM-level operations, - including those of :class:`.ColumnProperty`, :class:`.RelationshipProperty`, - and :class:`.CompositeProperty`. + including those of :class:`.ColumnProperty`, + :class:`.RelationshipProperty`, and :class:`.CompositeProperty`. .. note:: With the advent of Hybrid properties introduced in SQLAlchemy 0.7, as well as Core-level operator redefinition in @@ -274,10 +278,10 @@ class SomeMappedClass(Base): some_column = column_property(Column("some_column", String), - comparator_factory=MyColumnComparator) + comparator_factory=MyColumnComparator) some_relationship = relationship(SomeOtherClass, - comparator_factory=MyRelationshipComparator) + comparator_factory=MyRelationshipComparator) some_composite = composite( Column("a", String), Column("b", String), @@ -310,7 +314,6 @@ self._parentmapper = parentmapper self.adapter = adapter - def __clause_element__(self): raise NotImplementedError("%r" % self) @@ -345,8 +348,8 @@ query.join(Company.employees.of_type(Engineer)).\\ filter(Engineer.name=='foo') - :param \class_: a class or mapper indicating that criterion will be against - this specific subclass. + :param \class_: a class or mapper indicating that criterion will be + against this specific subclass. """ @@ -363,9 +366,9 @@ :param criterion: an optional ClauseElement formulated against the member class' table or attributes. - :param \**kwargs: key/value pairs corresponding to member class attribute - names which will be compared via equality to the corresponding - values. + :param \**kwargs: key/value pairs corresponding to member class + attribute names which will be compared via equality to the + corresponding values. """ @@ -381,9 +384,9 @@ :param criterion: an optional ClauseElement formulated against the member class' table or attributes. - :param \**kwargs: key/value pairs corresponding to member class attribute - names which will be compared via equality to the corresponding - values. + :param \**kwargs: key/value pairs corresponding to member class + attribute names which will be compared via equality to the + corresponding values. """ @@ -456,6 +459,7 @@ not mapper.class_manager._attr_has_impl(self.key): self.strategy.init_class_attribute(mapper) + class MapperOption(object): """Describe a modification to a Query.""" @@ -476,6 +480,7 @@ self.process_query(query) + class PropertyOption(MapperOption): """A MapperOption that is applied to a property off the mapper or one of its child mappers, identified by a dot-separated key @@ -685,6 +690,7 @@ return paths + class StrategizedOption(PropertyOption): """A MapperOption that affects which LoaderStrategy will be used for an operation by a StrategizedProperty. @@ -711,6 +717,7 @@ def get_strategy_class(self): raise NotImplementedError() + class LoaderStrategy(object): """Describe the loading behavior of a StrategizedProperty object. @@ -758,5 +765,3 @@ def __str__(self): return str(self.parent_property) - - diff -r 04d3ffa1e58a -r d0400a7fc12e lib/sqlalchemy/orm/loading.py --- a/lib/sqlalchemy/orm/loading.py Mon Nov 19 15:29:28 2012 -0500 +++ b/lib/sqlalchemy/orm/loading.py Mon Nov 19 17:19:24 2012 -0500 @@ -23,6 +23,7 @@ _new_runid = util.counter() + def instances(query, cursor, context): """Return an ORM result as an iterator.""" |