summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 01:19:47 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2019-01-06 18:23:11 -0500
commit1e278de4cc9a4181e0747640a960e80efcea1ca9 (patch)
tree13d0c035807613bfa07e734acad79b9c843cb8b0 /lib/sqlalchemy/ext
parent1e1a38e7801f410f244e4bbb44ec795ae152e04e (diff)
downloadsqlalchemy-1e278de4cc9a4181e0747640a960e80efcea1ca9.tar.gz
Post black reformatting
Applied on top of a pure run of black -l 79 in I7eda77fed3d8e73df84b3651fd6cfcfe858d4dc9, this set of changes resolves all remaining flake8 conditions for those codes we have enabled in setup.cfg. Included are resolutions for all remaining flake8 issues including shadowed builtins, long lines, import order, unused imports, duplicate imports, and docstring issues. Change-Id: I4f72d3ba1380dd601610ff80b8fb06a2aff8b0fe
Diffstat (limited to 'lib/sqlalchemy/ext')
-rw-r--r--lib/sqlalchemy/ext/__init__.py1
-rw-r--r--lib/sqlalchemy/ext/associationproxy.py38
-rw-r--r--lib/sqlalchemy/ext/automap.py12
-rw-r--r--lib/sqlalchemy/ext/baked.py17
-rw-r--r--lib/sqlalchemy/ext/declarative/__init__.py24
-rw-r--r--lib/sqlalchemy/ext/declarative/api.py49
-rw-r--r--lib/sqlalchemy/ext/declarative/base.py41
-rw-r--r--lib/sqlalchemy/ext/declarative/clsregistry.py21
-rw-r--r--lib/sqlalchemy/ext/horizontal_shard.py3
-rw-r--r--lib/sqlalchemy/ext/hybrid.py142
-rw-r--r--lib/sqlalchemy/ext/indexable.py8
-rw-r--r--lib/sqlalchemy/ext/instrumentation.py22
-rw-r--r--lib/sqlalchemy/ext/mutable.py16
-rw-r--r--lib/sqlalchemy/ext/orderinglist.py4
-rw-r--r--lib/sqlalchemy/ext/serializer.py40
15 files changed, 232 insertions, 206 deletions
diff --git a/lib/sqlalchemy/ext/__init__.py b/lib/sqlalchemy/ext/__init__.py
index 9fed09e2b..7219b28a5 100644
--- a/lib/sqlalchemy/ext/__init__.py
+++ b/lib/sqlalchemy/ext/__init__.py
@@ -7,4 +7,5 @@
from .. import util as _sa_util
+
_sa_util.dependencies.resolve_all("sqlalchemy.ext")
diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py
index 56b91ce0b..36c3fd415 100644
--- a/lib/sqlalchemy/ext/associationproxy.py
+++ b/lib/sqlalchemy/ext/associationproxy.py
@@ -14,11 +14,15 @@ See the example ``examples/association/proxied_association.py``.
"""
import operator
-from .. import exc, orm, util
-from ..orm import collections, interfaces
+
+from .. import exc
+from .. import inspect
+from .. import orm
+from .. import util
+from ..orm import collections
+from ..orm import interfaces
from ..sql import or_
from ..sql.operators import ColumnOperators
-from .. import inspect
def association_proxy(target_collection, attr, **kw):
@@ -316,7 +320,7 @@ class AssociationProxyInstance(object):
.. versionadded:: 1.3
- """
+ """ # noqa
def __init__(self, parent, owning_class, target_class, value_attr):
self.parent = parent
@@ -478,10 +482,10 @@ class AssociationProxyInstance(object):
def _initialize_scalar_accessors(self):
if self.parent.getset_factory:
- get, set = self.parent.getset_factory(None, self)
+ get, set_ = self.parent.getset_factory(None, self)
else:
- get, set = self.parent._default_getset(None)
- self._scalar_get, self._scalar_set = get, set
+ get, set_ = self.parent._default_getset(None)
+ self._scalar_get, self._scalar_set = get, set_
def _default_getset(self, collection_class):
attr = self.value_attr
@@ -954,11 +958,11 @@ class _AssociationList(_AssociationCollection):
def _create(self, value):
return self.creator(value)
- def _get(self, object):
- return self.getter(object)
+ def _get(self, object_):
+ return self.getter(object_)
- def _set(self, object, value):
- return self.setter(object, value)
+ def _set(self, object_, value):
+ return self.setter(object_, value)
def __getitem__(self, index):
if not isinstance(index, slice):
@@ -1164,11 +1168,11 @@ class _AssociationDict(_AssociationCollection):
def _create(self, key, value):
return self.creator(key, value)
- def _get(self, object):
- return self.getter(object)
+ def _get(self, object_):
+ return self.getter(object_)
- def _set(self, object, key, value):
- return self.setter(object, key, value)
+ def _set(self, object_, key, value):
+ return self.setter(object_, key, value)
def __getitem__(self, key):
return self._get(self.col[key])
@@ -1321,8 +1325,8 @@ class _AssociationSet(_AssociationCollection):
def _create(self, value):
return self.creator(value)
- def _get(self, object):
- return self.getter(object)
+ def _get(self, object_):
+ return self.getter(object_)
def __len__(self):
return len(self.col)
diff --git a/lib/sqlalchemy/ext/automap.py b/lib/sqlalchemy/ext/automap.py
index 747373a2a..60cc4dfe0 100644
--- a/lib/sqlalchemy/ext/automap.py
+++ b/lib/sqlalchemy/ext/automap.py
@@ -512,14 +512,16 @@ the :meth:`.AutomapBase.prepare` method is required; if not called, the classes
we've declared are in an un-mapped state.
-"""
+""" # noqa
from .declarative import declarative_base as _declarative_base
from .declarative.base import _DeferredMapperConfig
-from ..sql import and_
-from ..schema import ForeignKeyConstraint
-from ..orm import relationship, backref, interfaces
-from ..orm.mapper import _CONFIGURE_MUTEX
from .. import util
+from ..orm import backref
+from ..orm import interfaces
+from ..orm import relationship
+from ..orm.mapper import _CONFIGURE_MUTEX
+from ..schema import ForeignKeyConstraint
+from ..sql import and_
def classname_for_table(base, tablename, table):
diff --git a/lib/sqlalchemy/ext/baked.py b/lib/sqlalchemy/ext/baked.py
index f55231a09..4feba8959 100644
--- a/lib/sqlalchemy/ext/baked.py
+++ b/lib/sqlalchemy/ext/baked.py
@@ -13,16 +13,19 @@ compiled result to be fully cached.
"""
-from ..orm.query import Query
-from ..orm import strategy_options
-from ..orm.session import Session
-from ..sql import util as sql_util, func, literal_column
-from ..orm import exc as orm_exc
+import copy
+import logging
+
from .. import exc as sa_exc
from .. import util
+from ..orm import exc as orm_exc
+from ..orm import strategy_options
+from ..orm.query import Query
+from ..orm.session import Session
+from ..sql import func
+from ..sql import literal_column
+from ..sql import util as sql_util
-import copy
-import logging
log = logging.getLogger(__name__)
diff --git a/lib/sqlalchemy/ext/declarative/__init__.py b/lib/sqlalchemy/ext/declarative/__init__.py
index 2b0a37884..5eb6ebb2e 100644
--- a/lib/sqlalchemy/ext/declarative/__init__.py
+++ b/lib/sqlalchemy/ext/declarative/__init__.py
@@ -5,19 +5,17 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .api import (
- declarative_base,
- synonym_for,
- comparable_using,
- instrument_declarative,
- ConcreteBase,
- AbstractConcreteBase,
- DeclarativeMeta,
- DeferredReflection,
- has_inherited_table,
- declared_attr,
- as_declarative,
-)
+from .api import AbstractConcreteBase
+from .api import as_declarative
+from .api import comparable_using
+from .api import ConcreteBase
+from .api import declarative_base
+from .api import DeclarativeMeta
+from .api import declared_attr
+from .api import DeferredReflection
+from .api import has_inherited_table
+from .api import instrument_declarative
+from .api import synonym_for
__all__ = [
diff --git a/lib/sqlalchemy/ext/declarative/api.py b/lib/sqlalchemy/ext/declarative/api.py
index 987e92119..a4cbf3b52 100644
--- a/lib/sqlalchemy/ext/declarative/api.py
+++ b/lib/sqlalchemy/ext/declarative/api.py
@@ -7,30 +7,29 @@
"""Public API functions and helpers for declarative."""
-from ...schema import Table, MetaData, Column
-from ...orm import (
- synonym as _orm_synonym,
- comparable_property,
- interfaces,
- properties,
- attributes,
-)
-from ...orm.util import polymorphic_union
-from ...orm.base import _mapper_or_none
-from ...util import OrderedDict, hybridmethod, hybridproperty
-from ... import util
-from ... import exc
-import weakref
import re
+import weakref
-from .base import (
- _as_declarative,
- _declarative_constructor,
- _DeferredMapperConfig,
- _add_attribute,
- _del_attribute,
-)
+from .base import _add_attribute
+from .base import _as_declarative
+from .base import _declarative_constructor
+from .base import _DeferredMapperConfig
+from .base import _del_attribute
from .clsregistry import _class_resolver
+from ... import exc
+from ... import util
+from ...orm import attributes
+from ...orm import comparable_property
+from ...orm import interfaces
+from ...orm import properties
+from ...orm import synonym as _orm_synonym
+from ...orm.base import _mapper_or_none
+from ...orm.util import polymorphic_union
+from ...schema import MetaData
+from ...schema import Table
+from ...util import hybridmethod
+from ...util import hybridproperty
+from ...util import OrderedDict
def instrument_declarative(cls, registry, metadata):
@@ -258,7 +257,8 @@ class declared_attr(interfaces._MappedAttribute, property):
@declared_attr.cascading
def id(cls):
if has_inherited_table(cls):
- return Column(ForeignKey('myclass.id'), primary_key=True)
+ return Column(
+ ForeignKey('myclass.id'), primary_key=True)
else:
return Column(Integer, primary_key=True)
@@ -362,8 +362,9 @@ def declarative_base(
compatible callable to use as the meta type of the generated
declarative base class.
- .. versionchanged:: 1.1 if :paramref:`.declarative_base.cls` is a single class (rather
- than a tuple), the constructed base class will inherit its docstring.
+ .. versionchanged:: 1.1 if :paramref:`.declarative_base.cls` is a
+ single class (rather than a tuple), the constructed base class will
+ inherit its docstring.
.. seealso::
diff --git a/lib/sqlalchemy/ext/declarative/base.py b/lib/sqlalchemy/ext/declarative/base.py
index 07778f733..3c83b0b0e 100644
--- a/lib/sqlalchemy/ext/declarative/base.py
+++ b/lib/sqlalchemy/ext/declarative/base.py
@@ -6,20 +6,28 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""Internal implementation for declarative."""
-from ...schema import Table, Column
-from ...orm import mapper, class_mapper, synonym
-from ...orm.interfaces import MapperProperty
-from ...orm.properties import ColumnProperty, CompositeProperty
-from ...orm.attributes import QueryableAttribute
-from ...orm.base import _is_mapped_class, InspectionAttr
-from ... import util, exc
-from ...util import topological
-from ...sql import expression
-from ... import event
-from . import clsregistry
import collections
import weakref
+
from sqlalchemy.orm import instrumentation
+from . import clsregistry
+from ... import event
+from ... import exc
+from ... import util
+from ...orm import class_mapper
+from ...orm import mapper
+from ...orm import synonym
+from ...orm.attributes import QueryableAttribute
+from ...orm.base import _is_mapped_class
+from ...orm.base import InspectionAttr
+from ...orm.interfaces import MapperProperty
+from ...orm.properties import ColumnProperty
+from ...orm.properties import CompositeProperty
+from ...schema import Column
+from ...schema import Table
+from ...sql import expression
+from ...util import topological
+
declared_attr = declarative_props = None
@@ -228,9 +236,9 @@ class _MapperConfig(object):
# make a copy of it so a class-level dictionary
# is not overwritten when we update column-based
# arguments.
- mapper_args_fn = lambda: dict(
- cls.__mapper_args__
- ) # noqa
+ def mapper_args_fn():
+ return dict(cls.__mapper_args__)
+
elif name == "__tablename__":
check_decl = _check_declared_props_nocascade(
obj, name, cls
@@ -283,8 +291,9 @@ class _MapperConfig(object):
# defined attribute here to allow a clean
# override, if there's another
# subclass below then it still tries to use
- # this. not sure if there is enough information
- # here to add this as a feature later on.
+ # this. not sure if there is enough
+ # information here to add this as a feature
+ # later on.
util.warn(
"Attribute '%s' on class %s cannot be "
"processed due to "
diff --git a/lib/sqlalchemy/ext/declarative/clsregistry.py b/lib/sqlalchemy/ext/declarative/clsregistry.py
index c52ae4a2f..6f7c7c2be 100644
--- a/lib/sqlalchemy/ext/declarative/clsregistry.py
+++ b/lib/sqlalchemy/ext/declarative/clsregistry.py
@@ -10,18 +10,19 @@ This system allows specification of classes and expressions used in
:func:`.relationship` using strings.
"""
-from ...orm.properties import (
- ColumnProperty,
- RelationshipProperty,
- SynonymProperty,
-)
-from ...schema import _get_table_key
-from ...orm import class_mapper, interfaces
-from ... import util
-from ... import inspection
-from ... import exc
import weakref
+from ... import exc
+from ... import inspection
+from ... import util
+from ...orm import class_mapper
+from ...orm import interfaces
+from ...orm.properties import ColumnProperty
+from ...orm.properties import RelationshipProperty
+from ...orm.properties import SynonymProperty
+from ...schema import _get_table_key
+
+
# strong references to registries which we place in
# the _decl_class_registry, which is usually weak referencing.
# the internal registries here link to classes with weakrefs and remove
diff --git a/lib/sqlalchemy/ext/horizontal_shard.py b/lib/sqlalchemy/ext/horizontal_shard.py
index 7248e5b4d..dda0bc5ba 100644
--- a/lib/sqlalchemy/ext/horizontal_shard.py
+++ b/lib/sqlalchemy/ext/horizontal_shard.py
@@ -17,8 +17,9 @@ the source distribution.
from .. import inspect
from .. import util
-from ..orm.session import Session
from ..orm.query import Query
+from ..orm.session import Session
+
__all__ = ["ShardedSession", "ShardedQuery"]
diff --git a/lib/sqlalchemy/ext/hybrid.py b/lib/sqlalchemy/ext/hybrid.py
index d51a083da..729fe1202 100644
--- a/lib/sqlalchemy/ext/hybrid.py
+++ b/lib/sqlalchemy/ext/hybrid.py
@@ -16,8 +16,8 @@ dependencies on the rest of SQLAlchemy. It can, in theory, work with
any descriptor-based expression system.
Consider a mapping ``Interval``, representing integer ``start`` and ``end``
-values. We can define higher level functions on mapped classes that produce
-SQL expressions at the class level, and Python expression evaluation at the
+values. We can define higher level functions on mapped classes that produce SQL
+expressions at the class level, and Python expression evaluation at the
instance level. Below, each function decorated with :class:`.hybrid_method` or
:class:`.hybrid_property` may receive ``self`` as an instance of the class, or
as the class itself::
@@ -410,7 +410,8 @@ idiosyncratic behavior on the SQL side.
.. note:: The :meth:`.hybrid_property.comparator` decorator introduced
in this section **replaces** the use of the
- :meth:`.hybrid_property.expression` decorator. They cannot be used together.
+ :meth:`.hybrid_property.expression` decorator.
+ They cannot be used together.
The example class below allows case-insensitive comparisons on the attribute
named ``word_insensitive``::
@@ -496,13 +497,12 @@ Above, the ``FirstNameLastName`` class refers to the hybrid from
``FirstNameOnly.name`` to repurpose its getter and setter for the subclass.
When overriding :meth:`.hybrid_property.expression` and
-:meth:`.hybrid_property.comparator` alone as the first reference
-to the superclass, these names conflict
-with the same-named accessors on the class-level :class:`.QueryableAttribute`
-object returned at the class level. To override these methods when
-referring directly to the parent class descriptor, add
-the special qualifier :attr:`.hybrid_property.overrides`, which will
-de-reference the instrumented attribute back to the hybrid object::
+:meth:`.hybrid_property.comparator` alone as the first reference to the
+superclass, these names conflict with the same-named accessors on the class-
+level :class:`.QueryableAttribute` object returned at the class level. To
+override these methods when referring directly to the parent class descriptor,
+add the special qualifier :attr:`.hybrid_property.overrides`, which will de-
+reference the instrumented attribute back to the hybrid object::
class FirstNameLastName(FirstNameOnly):
# ...
@@ -520,19 +520,18 @@ de-reference the instrumented attribute back to the hybrid object::
Hybrid Value Objects
--------------------
-Note in our previous example, if we were to compare the
-``word_insensitive`` attribute of a ``SearchWord`` instance to a plain
-Python string, the plain Python string would not be coerced to lower
-case - the ``CaseInsensitiveComparator`` we built, being returned by
+Note in our previous example, if we were to compare the ``word_insensitive``
+attribute of a ``SearchWord`` instance to a plain Python string, the plain
+Python string would not be coerced to lower case - the
+``CaseInsensitiveComparator`` we built, being returned by
``@word_insensitive.comparator``, only applies to the SQL side.
-A more comprehensive form of the custom comparator is to construct a
-*Hybrid Value Object*. This technique applies the target value or
-expression to a value object which is then returned by the accessor in
-all cases. The value object allows control of all operations upon
-the value as well as how compared values are treated, both on the SQL
-expression side as well as the Python value side. Replacing the
-previous ``CaseInsensitiveComparator`` class with a new
+A more comprehensive form of the custom comparator is to construct a *Hybrid
+Value Object*. This technique applies the target value or expression to a value
+object which is then returned by the accessor in all cases. The value object
+allows control of all operations upon the value as well as how compared values
+are treated, both on the SQL expression side as well as the Python value side.
+Replacing the previous ``CaseInsensitiveComparator`` class with a new
``CaseInsensitiveWord`` class::
class CaseInsensitiveWord(Comparator):
@@ -560,13 +559,12 @@ previous ``CaseInsensitiveComparator`` class with a new
key = 'word'
"Label to apply to Query tuple results"
-Above, the ``CaseInsensitiveWord`` object represents ``self.word``,
-which may be a SQL function, or may be a Python native. By
-overriding ``operate()`` and ``__clause_element__()`` to work in terms
-of ``self.word``, all comparison operations will work against the
-"converted" form of ``word``, whether it be SQL side or Python side.
-Our ``SearchWord`` class can now deliver the ``CaseInsensitiveWord``
-object unconditionally from a single hybrid call::
+Above, the ``CaseInsensitiveWord`` object represents ``self.word``, which may
+be a SQL function, or may be a Python native. By overriding ``operate()`` and
+``__clause_element__()`` to work in terms of ``self.word``, all comparison
+operations will work against the "converted" form of ``word``, whether it be
+SQL side or Python side. Our ``SearchWord`` class can now deliver the
+``CaseInsensitiveWord`` object unconditionally from a single hybrid call::
class SearchWord(Base):
__tablename__ = 'searchword'
@@ -577,10 +575,9 @@ object unconditionally from a single hybrid call::
def word_insensitive(self):
return CaseInsensitiveWord(self.word)
-The ``word_insensitive`` attribute now has case-insensitive comparison
-behavior universally, including SQL expression vs. Python expression
-(note the Python value is converted to lower case on the Python side
-here)::
+The ``word_insensitive`` attribute now has case-insensitive comparison behavior
+universally, including SQL expression vs. Python expression (note the Python
+value is converted to lower case on the Python side here)::
>>> print Session().query(SearchWord).filter_by(word_insensitive="Trucks")
SELECT searchword.id AS searchword_id, searchword.word AS searchword_word
@@ -612,9 +609,9 @@ Python only expression::
>>> print ws1.word_insensitive
someword
-The Hybrid Value pattern is very useful for any kind of value that may
-have multiple representations, such as timestamps, time deltas, units
-of measurement, currencies and encrypted passwords.
+The Hybrid Value pattern is very useful for any kind of value that may have
+multiple representations, such as timestamps, time deltas, units of
+measurement, currencies and encrypted passwords.
.. seealso::
@@ -631,17 +628,17 @@ of measurement, currencies and encrypted passwords.
Building Transformers
----------------------
-A *transformer* is an object which can receive a :class:`.Query`
-object and return a new one. The :class:`.Query` object includes a
-method :meth:`.with_transformation` that returns a new :class:`.Query`
-transformed by the given function.
+A *transformer* is an object which can receive a :class:`.Query` object and
+return a new one. The :class:`.Query` object includes a method
+:meth:`.with_transformation` that returns a new :class:`.Query` transformed by
+the given function.
We can combine this with the :class:`.Comparator` class to produce one type
of recipe which can both set up the FROM clause of a query as well as assign
filtering criterion.
-Consider a mapped class ``Node``, which assembles using adjacency list
-into a hierarchical tree pattern::
+Consider a mapped class ``Node``, which assembles using adjacency list into a
+hierarchical tree pattern::
from sqlalchemy import Column, Integer, ForeignKey
from sqlalchemy.orm import relationship
@@ -654,9 +651,9 @@ into a hierarchical tree pattern::
parent_id = Column(Integer, ForeignKey('node.id'))
parent = relationship("Node", remote_side=id)
-Suppose we wanted to add an accessor ``grandparent``. This would
-return the ``parent`` of ``Node.parent``. When we have an instance of
-``Node``, this is simple::
+Suppose we wanted to add an accessor ``grandparent``. This would return the
+``parent`` of ``Node.parent``. When we have an instance of ``Node``, this is
+simple::
from sqlalchemy.ext.hybrid import hybrid_property
@@ -667,13 +664,12 @@ return the ``parent`` of ``Node.parent``. When we have an instance of
def grandparent(self):
return self.parent.parent
-For the expression, things are not so clear. We'd need to construct
-a :class:`.Query` where we :meth:`~.Query.join` twice along
-``Node.parent`` to get to the ``grandparent``. We can instead return
-a transforming callable that we'll combine with the
-:class:`.Comparator` class to receive any :class:`.Query` object, and
-return a new one that's joined to the ``Node.parent`` attribute and
-filtered based on the given criterion::
+For the expression, things are not so clear. We'd need to construct a
+:class:`.Query` where we :meth:`~.Query.join` twice along ``Node.parent`` to
+get to the ``grandparent``. We can instead return a transforming callable
+that we'll combine with the :class:`.Comparator` class to receive any
+:class:`.Query` object, and return a new one that's joined to the
+``Node.parent`` attribute and filtered based on the given criterion::
from sqlalchemy.ext.hybrid import Comparator
@@ -702,17 +698,15 @@ filtered based on the given criterion::
def grandparent(cls):
return GrandparentTransformer(cls)
-The ``GrandparentTransformer`` overrides the core
-:meth:`.Operators.operate` method at the base of the
-:class:`.Comparator` hierarchy to return a query-transforming
-callable, which then runs the given comparison operation in a
-particular context. Such as, in the example above, the ``operate``
-method is called, given the :attr:`.Operators.eq` callable as well as
-the right side of the comparison ``Node(id=5)``. A function
-``transform`` is then returned which will transform a :class:`.Query`
-first to join to ``Node.parent``, then to compare ``parent_alias``
-using :attr:`.Operators.eq` against the left and right sides, passing
-into :class:`.Query.filter`:
+The ``GrandparentTransformer`` overrides the core :meth:`.Operators.operate`
+method at the base of the :class:`.Comparator` hierarchy to return a query-
+transforming callable, which then runs the given comparison operation in a
+particular context. Such as, in the example above, the ``operate`` method is
+called, given the :attr:`.Operators.eq` callable as well as the right side of
+the comparison ``Node(id=5)``. A function ``transform`` is then returned which
+will transform a :class:`.Query` first to join to ``Node.parent``, then to
+compare ``parent_alias`` using :attr:`.Operators.eq` against the left and right
+sides, passing into :class:`.Query.filter`:
.. sourcecode:: pycon+sql
@@ -726,12 +720,12 @@ into :class:`.Query.filter`:
WHERE :param_1 = node_1.parent_id
{stop}
-We can modify the pattern to be more verbose but flexible by separating
-the "join" step from the "filter" step. The tricky part here is ensuring
-that successive instances of ``GrandparentTransformer`` use the same
+We can modify the pattern to be more verbose but flexible by separating the
+"join" step from the "filter" step. The tricky part here is ensuring that
+successive instances of ``GrandparentTransformer`` use the same
:class:`.AliasedClass` object against ``Node``. Below we use a simple
-memoizing approach that associates a ``GrandparentTransformer``
-with each class::
+memoizing approach that associates a ``GrandparentTransformer`` with each
+class::
class Node(Base):
@@ -769,14 +763,16 @@ with each class::
WHERE :param_1 = node_1.parent_id
{stop}
-The "transformer" pattern is an experimental pattern that starts
-to make usage of some functional programming paradigms.
-While it's only recommended for advanced and/or patient developers,
-there's probably a whole lot of amazing things it can be used for.
+The "transformer" pattern is an experimental pattern that starts to make usage
+of some functional programming paradigms. While it's only recommended for
+advanced and/or patient developers, there's probably a whole lot of amazing
+things it can be used for.
-"""
+""" # noqa
from .. import util
-from ..orm import attributes, interfaces
+from ..orm import attributes
+from ..orm import interfaces
+
HYBRID_METHOD = util.symbol("HYBRID_METHOD")
"""Symbol indicating an :class:`InspectionAttr` that's
diff --git a/lib/sqlalchemy/ext/indexable.py b/lib/sqlalchemy/ext/indexable.py
index 368e5b00a..a9100728e 100644
--- a/lib/sqlalchemy/ext/indexable.py
+++ b/lib/sqlalchemy/ext/indexable.py
@@ -174,10 +174,6 @@ data structure does not exist, and a set operation is called:
rules.
-
-
-
-
Subclassing
===========
@@ -224,12 +220,12 @@ The above query will render::
FROM person
WHERE CAST(person.data ->> %(data_1)s AS INTEGER) < %(param_1)s
-"""
+""" # noqa
from __future__ import absolute_import
from sqlalchemy import inspect
-from ..orm.attributes import flag_modified
from ..ext.hybrid import hybrid_property
+from ..orm.attributes import flag_modified
__all__ = ["index_property"]
diff --git a/lib/sqlalchemy/ext/instrumentation.py b/lib/sqlalchemy/ext/instrumentation.py
index b2b8dd7c5..ae62dca08 100644
--- a/lib/sqlalchemy/ext/instrumentation.py
+++ b/lib/sqlalchemy/ext/instrumentation.py
@@ -26,18 +26,20 @@ see the example :ref:`examples_instrumentation`.
being used to determine class instrumentation resolution.
"""
-from ..orm import instrumentation as orm_instrumentation
-from ..orm.instrumentation import (
- ClassManager,
- InstrumentationFactory,
- _default_state_getter,
- _default_dict_getter,
- _default_manager_getter,
-)
-from ..orm import attributes, collections, base as orm_base
+import weakref
+
from .. import util
+from ..orm import attributes
+from ..orm import base as orm_base
+from ..orm import collections
from ..orm import exc as orm_exc
-import weakref
+from ..orm import instrumentation as orm_instrumentation
+from ..orm.instrumentation import _default_dict_getter
+from ..orm.instrumentation import _default_manager_getter
+from ..orm.instrumentation import _default_state_getter
+from ..orm.instrumentation import ClassManager
+from ..orm.instrumentation import InstrumentationFactory
+
INSTRUMENTATION_MANAGER = "__sa_instrumentation_manager__"
"""Attribute, elects custom instrumentation when present on a mapped class.
diff --git a/lib/sqlalchemy/ext/mutable.py b/lib/sqlalchemy/ext/mutable.py
index 0f6ccdc33..96372639f 100644
--- a/lib/sqlalchemy/ext/mutable.py
+++ b/lib/sqlalchemy/ext/mutable.py
@@ -370,12 +370,16 @@ pickling process of the parent's object-relational state so that the
:meth:`MutableBase._parents` collection is restored to all ``Point`` objects.
"""
+import weakref
+
+from .. import event
+from .. import types
+from ..orm import Mapper
+from ..orm import mapper
+from ..orm import object_mapper
from ..orm.attributes import flag_modified
-from .. import event, types
-from ..orm import mapper, object_mapper, Mapper
-from ..util import memoized_property
from ..sql.base import SchemaEventTarget
-import weakref
+from ..util import memoized_property
class MutableBase(object):
@@ -479,7 +483,7 @@ class MutableBase(object):
if not attrs or listen_keys.intersection(attrs):
load(state)
- def set(target, value, oldvalue, initiator):
+ def set_(target, value, oldvalue, initiator):
"""Listen for set/replace events on the target
data member.
@@ -519,7 +523,7 @@ class MutableBase(object):
parent_cls, "refresh_flush", load_attrs, raw=True, propagate=True
)
event.listen(
- attribute, "set", set, raw=True, retval=True, propagate=True
+ attribute, "set", set_, raw=True, retval=True, propagate=True
)
event.listen(parent_cls, "pickle", pickle, raw=True, propagate=True)
event.listen(
diff --git a/lib/sqlalchemy/ext/orderinglist.py b/lib/sqlalchemy/ext/orderinglist.py
index 2a8522120..659211044 100644
--- a/lib/sqlalchemy/ext/orderinglist.py
+++ b/lib/sqlalchemy/ext/orderinglist.py
@@ -119,8 +119,10 @@ start numbering at 1 or some other integer, provide ``count_from=1``.
"""
-from ..orm.collections import collection, collection_adapter
from .. import util
+from ..orm.collections import collection
+from ..orm.collections import collection_adapter
+
__all__ = ["ordering_list"]
diff --git a/lib/sqlalchemy/ext/serializer.py b/lib/sqlalchemy/ext/serializer.py
index 3adcec34f..ae983946a 100644
--- a/lib/sqlalchemy/ext/serializer.py
+++ b/lib/sqlalchemy/ext/serializer.py
@@ -53,15 +53,21 @@ needed for:
"""
+import re
+
+from .. import Column
+from .. import Table
+from ..engine import Engine
from ..orm import class_mapper
-from ..orm.session import Session
-from ..orm.mapper import Mapper
-from ..orm.interfaces import MapperProperty
from ..orm.attributes import QueryableAttribute
-from .. import Table, Column
-from ..engine import Engine
-from ..util import pickle, byte_buffer, b64encode, b64decode, text_type
-import re
+from ..orm.interfaces import MapperProperty
+from ..orm.mapper import Mapper
+from ..orm.session import Session
+from ..util import b64decode
+from ..util import b64encode
+from ..util import byte_buffer
+from ..util import pickle
+from ..util import text_type
__all__ = ["Serializer", "Deserializer", "dumps", "loads"]
@@ -75,29 +81,29 @@ def Serializer(*args, **kw):
if isinstance(obj, QueryableAttribute):
cls = obj.impl.class_
key = obj.impl.key
- id = "attribute:" + key + ":" + b64encode(pickle.dumps(cls))
+ id_ = "attribute:" + key + ":" + b64encode(pickle.dumps(cls))
elif isinstance(obj, Mapper) and not obj.non_primary:
- id = "mapper:" + b64encode(pickle.dumps(obj.class_))
+ id_ = "mapper:" + b64encode(pickle.dumps(obj.class_))
elif isinstance(obj, MapperProperty) and not obj.parent.non_primary:
- id = (
+ id_ = (
"mapperprop:"
+ b64encode(pickle.dumps(obj.parent.class_))
+ ":"
+ obj.key
)
elif isinstance(obj, Table):
- id = "table:" + text_type(obj.key)
+ id_ = "table:" + text_type(obj.key)
elif isinstance(obj, Column) and isinstance(obj.table, Table):
- id = (
+ id_ = (
"column:" + text_type(obj.table.key) + ":" + text_type(obj.key)
)
elif isinstance(obj, Session):
- id = "session:"
+ id_ = "session:"
elif isinstance(obj, Engine):
- id = "engine:"
+ id_ = "engine:"
else:
return None
- return id
+ return id_
pickler.persistent_id = persistent_id
return pickler
@@ -121,8 +127,8 @@ def Deserializer(file, metadata=None, scoped_session=None, engine=None):
else:
return None
- def persistent_load(id):
- m = our_ids.match(text_type(id))
+ def persistent_load(id_):
+ m = our_ids.match(text_type(id_))
if not m:
return None
else: