summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
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
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')
-rw-r--r--lib/sqlalchemy/__init__.py240
-rw-r--r--lib/sqlalchemy/connectors/mxodbc.py4
-rw-r--r--lib/sqlalchemy/connectors/pyodbc.py5
-rw-r--r--lib/sqlalchemy/connectors/zxJDBC.py1
-rw-r--r--lib/sqlalchemy/databases/__init__.py13
-rw-r--r--lib/sqlalchemy/dialects/__init__.py1
-rw-r--r--lib/sqlalchemy/dialects/firebird/__init__.py28
-rw-r--r--lib/sqlalchemy/dialects/firebird/base.py52
-rw-r--r--lib/sqlalchemy/dialects/firebird/fdb.py5
-rw-r--r--lib/sqlalchemy/dialects/firebird/kinterbasdb.py14
-rw-r--r--lib/sqlalchemy/dialects/mssql/__init__.py71
-rw-r--r--lib/sqlalchemy/dialects/mssql/adodbapi.py7
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py81
-rw-r--r--lib/sqlalchemy/dialects/mssql/information_schema.py12
-rw-r--r--lib/sqlalchemy/dialects/mssql/mxodbc.py16
-rw-r--r--lib/sqlalchemy/dialects/mssql/pymssql.py13
-rw-r--r--lib/sqlalchemy/dialects/mssql/pyodbc.py21
-rw-r--r--lib/sqlalchemy/dialects/mssql/zxjdbc.py10
-rw-r--r--lib/sqlalchemy/dialects/mysql/__init__.py98
-rw-r--r--lib/sqlalchemy/dialects/mysql/base.py150
-rw-r--r--lib/sqlalchemy/dialects/mysql/cymysql.py12
-rw-r--r--lib/sqlalchemy/dialects/mysql/dml.py9
-rw-r--r--lib/sqlalchemy/dialects/mysql/enumerated.py4
-rw-r--r--lib/sqlalchemy/dialects/mysql/gaerdbms.py11
-rw-r--r--lib/sqlalchemy/dialects/mysql/json.py2
-rw-r--r--lib/sqlalchemy/dialects/mysql/mysqlconnector.py29
-rw-r--r--lib/sqlalchemy/dialects/mysql/mysqldb.py13
-rw-r--r--lib/sqlalchemy/dialects/mysql/oursql.py8
-rw-r--r--lib/sqlalchemy/dialects/mysql/pymysql.py10
-rw-r--r--lib/sqlalchemy/dialects/mysql/pyodbc.py8
-rw-r--r--lib/sqlalchemy/dialects/mysql/reflection.py11
-rw-r--r--lib/sqlalchemy/dialects/mysql/types.py6
-rw-r--r--lib/sqlalchemy/dialects/mysql/zxjdbc.py14
-rw-r--r--lib/sqlalchemy/dialects/oracle/__init__.py46
-rw-r--r--lib/sqlalchemy/dialects/oracle/base.py75
-rw-r--r--lib/sqlalchemy/dialects/oracle/cx_oracle.py66
-rw-r--r--lib/sqlalchemy/dialects/oracle/zxjdbc.py37
-rw-r--r--lib/sqlalchemy/dialects/postgresql/__init__.py108
-rw-r--r--lib/sqlalchemy/dialects/postgresql/array.py21
-rw-r--r--lib/sqlalchemy/dialects/postgresql/base.py82
-rw-r--r--lib/sqlalchemy/dialects/postgresql/dml.py15
-rw-r--r--lib/sqlalchemy/dialects/postgresql/ext.py10
-rw-r--r--lib/sqlalchemy/dialects/postgresql/hstore.py5
-rw-r--r--lib/sqlalchemy/dialects/postgresql/json.py12
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pg8000.py37
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg2.py72
-rw-r--r--lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py8
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pygresql.py34
-rw-r--r--lib/sqlalchemy/dialects/postgresql/pypostgresql.py14
-rw-r--r--lib/sqlalchemy/dialects/postgresql/ranges.py1
-rw-r--r--lib/sqlalchemy/dialects/postgresql/zxjdbc.py3
-rw-r--r--lib/sqlalchemy/dialects/sqlite/__init__.py38
-rw-r--r--lib/sqlalchemy/dialects/sqlite/base.py102
-rw-r--r--lib/sqlalchemy/dialects/sqlite/pysqlcipher.py9
-rw-r--r--lib/sqlalchemy/dialects/sqlite/pysqlite.py27
-rw-r--r--lib/sqlalchemy/dialects/sybase/__init__.py54
-rw-r--r--lib/sqlalchemy/dialects/sybase/base.py73
-rw-r--r--lib/sqlalchemy/dialects/sybase/mxodbc.py2
-rw-r--r--lib/sqlalchemy/dialects/sybase/pyodbc.py17
-rw-r--r--lib/sqlalchemy/dialects/sybase/pysybase.py16
-rw-r--r--lib/sqlalchemy/engine/__init__.py66
-rw-r--r--lib/sqlalchemy/engine/base.py49
-rw-r--r--lib/sqlalchemy/engine/default.py33
-rw-r--r--lib/sqlalchemy/engine/interfaces.py9
-rw-r--r--lib/sqlalchemy/engine/reflection.py9
-rw-r--r--lib/sqlalchemy/engine/result.py32
-rw-r--r--lib/sqlalchemy/engine/strategies.py14
-rw-r--r--lib/sqlalchemy/engine/threadlocal.py9
-rw-r--r--lib/sqlalchemy/engine/url.py9
-rw-r--r--lib/sqlalchemy/engine/util.py6
-rw-r--r--lib/sqlalchemy/event/__init__.py14
-rw-r--r--lib/sqlalchemy/event/api.py4
-rw-r--r--lib/sqlalchemy/event/attr.py15
-rw-r--r--lib/sqlalchemy/event/base.py5
-rw-r--r--lib/sqlalchemy/event/registry.py12
-rw-r--r--lib/sqlalchemy/events.py24
-rw-r--r--lib/sqlalchemy/exc.py2
-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
-rw-r--r--lib/sqlalchemy/inspection.py4
-rw-r--r--lib/sqlalchemy/interfaces.py3
-rw-r--r--lib/sqlalchemy/log.py5
-rw-r--r--lib/sqlalchemy/orm/__init__.py101
-rw-r--r--lib/sqlalchemy/orm/attributes.py60
-rw-r--r--lib/sqlalchemy/orm/base.py10
-rw-r--r--lib/sqlalchemy/orm/collections.py8
-rw-r--r--lib/sqlalchemy/orm/dependency.py26
-rw-r--r--lib/sqlalchemy/orm/deprecated_interfaces.py3
-rw-r--r--lib/sqlalchemy/orm/descriptor_props.py19
-rw-r--r--lib/sqlalchemy/orm/dynamic.py21
-rw-r--r--lib/sqlalchemy/orm/evaluator.py3
-rw-r--r--lib/sqlalchemy/orm/events.py20
-rw-r--r--lib/sqlalchemy/orm/exc.py4
-rw-r--r--lib/sqlalchemy/orm/identity.py7
-rw-r--r--lib/sqlalchemy/orm/instrumentation.py11
-rw-r--r--lib/sqlalchemy/orm/interfaces.py28
-rw-r--r--lib/sqlalchemy/orm/loading.py19
-rw-r--r--lib/sqlalchemy/orm/mapper.py87
-rw-r--r--lib/sqlalchemy/orm/path_registry.py10
-rw-r--r--lib/sqlalchemy/orm/persistence.py45
-rw-r--r--lib/sqlalchemy/orm/properties.py14
-rw-r--r--lib/sqlalchemy/orm/query.py93
-rw-r--r--lib/sqlalchemy/orm/relationships.py90
-rw-r--r--lib/sqlalchemy/orm/scoping.py13
-rw-r--r--lib/sqlalchemy/orm/session.py53
-rw-r--r--lib/sqlalchemy/orm/state.py39
-rw-r--r--lib/sqlalchemy/orm/strategies.py91
-rw-r--r--lib/sqlalchemy/orm/strategy_options.py37
-rw-r--r--lib/sqlalchemy/orm/sync.py4
-rw-r--r--lib/sqlalchemy/orm/unitofwork.py10
-rw-r--r--lib/sqlalchemy/orm/util.py67
-rw-r--r--lib/sqlalchemy/pool/__init__.py41
-rw-r--r--lib/sqlalchemy/pool/base.py6
-rw-r--r--lib/sqlalchemy/pool/dbapi_proxy.py1
-rw-r--r--lib/sqlalchemy/pool/impl.py5
-rw-r--r--lib/sqlalchemy/processors.py37
-rw-r--r--lib/sqlalchemy/schema.py104
-rw-r--r--lib/sqlalchemy/sql/__init__.py149
-rw-r--r--lib/sqlalchemy/sql/annotation.py2
-rw-r--r--lib/sqlalchemy/sql/base.py17
-rw-r--r--lib/sqlalchemy/sql/compiler.py31
-rw-r--r--lib/sqlalchemy/sql/crud.py34
-rw-r--r--lib/sqlalchemy/sql/ddl.py16
-rw-r--r--lib/sqlalchemy/sql/default_comparator.py54
-rw-r--r--lib/sqlalchemy/sql/dml.py54
-rw-r--r--lib/sqlalchemy/sql/elements.py59
-rw-r--r--lib/sqlalchemy/sql/expression.py184
-rw-r--r--lib/sqlalchemy/sql/functions.py56
-rw-r--r--lib/sqlalchemy/sql/naming.py28
-rw-r--r--lib/sqlalchemy/sql/operators.py41
-rw-r--r--lib/sqlalchemy/sql/schema.py64
-rw-r--r--lib/sqlalchemy/sql/selectable.py99
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py120
-rw-r--r--lib/sqlalchemy/sql/type_api.py19
-rw-r--r--lib/sqlalchemy/sql/util.py52
-rw-r--r--lib/sqlalchemy/sql/visitors.py4
-rw-r--r--lib/sqlalchemy/testing/__init__.py108
-rw-r--r--lib/sqlalchemy/testing/assertions.py33
-rw-r--r--lib/sqlalchemy/testing/assertsql.py13
-rw-r--r--lib/sqlalchemy/testing/engines.py8
-rw-r--r--lib/sqlalchemy/testing/entities.py3
-rw-r--r--lib/sqlalchemy/testing/exclusions.py5
-rw-r--r--lib/sqlalchemy/testing/fixtures.py21
-rw-r--r--lib/sqlalchemy/testing/mock.py14
-rw-r--r--lib/sqlalchemy/testing/plugin/bootstrap.py1
-rw-r--r--lib/sqlalchemy/testing/plugin/noseplugin.py3
-rw-r--r--lib/sqlalchemy/testing/plugin/plugin_base.py10
-rw-r--r--lib/sqlalchemy/testing/plugin/pytestplugin.py8
-rw-r--r--lib/sqlalchemy/testing/profiling.py15
-rw-r--r--lib/sqlalchemy/testing/provision.py22
-rw-r--r--lib/sqlalchemy/testing/replay_fixture.py24
-rw-r--r--lib/sqlalchemy/testing/requirements.py17
-rw-r--r--lib/sqlalchemy/testing/runner.py4
-rw-r--r--lib/sqlalchemy/testing/schema.py8
-rw-r--r--lib/sqlalchemy/testing/suite/__init__.py20
-rw-r--r--lib/sqlalchemy/testing/suite/test_cte.py16
-rw-r--r--lib/sqlalchemy/testing/suite/test_ddl.py12
-rw-r--r--lib/sqlalchemy/testing/suite/test_dialect.py17
-rw-r--r--lib/sqlalchemy/testing/suite/test_insert.py19
-rw-r--r--lib/sqlalchemy/testing/suite/test_reflection.py43
-rw-r--r--lib/sqlalchemy/testing/suite/test_results.py23
-rw-r--r--lib/sqlalchemy/testing/suite/test_select.py31
-rw-r--r--lib/sqlalchemy/testing/suite/test_sequence.py16
-rw-r--r--lib/sqlalchemy/testing/suite/test_types.py59
-rw-r--r--lib/sqlalchemy/testing/suite/test_update_delete.py10
-rw-r--r--lib/sqlalchemy/testing/util.py10
-rw-r--r--lib/sqlalchemy/testing/warnings.py3
-rw-r--r--lib/sqlalchemy/types.py116
-rw-r--r--lib/sqlalchemy/util/__init__.py274
-rw-r--r--lib/sqlalchemy/util/_collections.py28
-rw-r--r--lib/sqlalchemy/util/compat.py68
-rw-r--r--lib/sqlalchemy/util/deprecations.py9
-rw-r--r--lib/sqlalchemy/util/langhelpers.py23
-rw-r--r--lib/sqlalchemy/util/queue.py1
-rw-r--r--lib/sqlalchemy/util/topological.py3
188 files changed, 3270 insertions, 2843 deletions
diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py
index 171f23028..3df12f5c9 100644
--- a/lib/sqlalchemy/__init__.py
+++ b/lib/sqlalchemy/__init__.py
@@ -5,130 +5,122 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
+from . import util as _util # noqa
+from .inspection import inspect # noqa
+from .schema import BLANK_SCHEMA # noqa
+from .schema import CheckConstraint # noqa
+from .schema import Column # noqa
+from .schema import ColumnDefault # noqa
+from .schema import Constraint # noqa
+from .schema import DDL # noqa
+from .schema import DefaultClause # noqa
+from .schema import FetchedValue # noqa
+from .schema import ForeignKey # noqa
+from .schema import ForeignKeyConstraint # noqa
+from .schema import Index # noqa
+from .schema import MetaData # noqa
+from .schema import PassiveDefault # noqa
+from .schema import PrimaryKeyConstraint # noqa
+from .schema import Sequence # noqa
+from .schema import Table # noqa
+from .schema import ThreadLocalMetaData # noqa
+from .schema import UniqueConstraint # noqa
+from .sql import alias # noqa
+from .sql import all_ # noqa
+from .sql import and_ # noqa
+from .sql import any_ # noqa
+from .sql import asc # noqa
+from .sql import between # noqa
+from .sql import bindparam # noqa
+from .sql import case # noqa
+from .sql import cast # noqa
+from .sql import collate # noqa
+from .sql import column # noqa
+from .sql import delete # noqa
+from .sql import desc # noqa
+from .sql import distinct # noqa
+from .sql import except_ # noqa
+from .sql import except_all # noqa
+from .sql import exists # noqa
+from .sql import extract # noqa
+from .sql import false # noqa
+from .sql import func # noqa
+from .sql import funcfilter # noqa
+from .sql import insert # noqa
+from .sql import intersect # noqa
+from .sql import intersect_all # noqa
+from .sql import join # noqa
+from .sql import lateral # noqa
+from .sql import literal # noqa
+from .sql import literal_column # noqa
+from .sql import modifier # noqa
+from .sql import not_ # noqa
+from .sql import null # noqa
+from .sql import nullsfirst # noqa
+from .sql import nullslast # noqa
+from .sql import or_ # noqa
+from .sql import outerjoin # noqa
+from .sql import outparam # noqa
+from .sql import over # noqa
+from .sql import select # noqa
+from .sql import subquery # noqa
+from .sql import table # noqa
+from .sql import tablesample # noqa
+from .sql import text # noqa
+from .sql import true # noqa
+from .sql import tuple_ # noqa
+from .sql import type_coerce # noqa
+from .sql import union # noqa
+from .sql import union_all # noqa
+from .sql import update # noqa
+from .sql import within_group # noqa
+from .types import ARRAY # noqa
+from .types import BIGINT # noqa
+from .types import BigInteger # noqa
+from .types import BINARY # noqa
+from .types import Binary # noqa
+from .types import BLOB # noqa
+from .types import BOOLEAN # noqa
+from .types import Boolean # noqa
+from .types import CHAR # noqa
+from .types import CLOB # noqa
+from .types import DATE # noqa
+from .types import Date # noqa
+from .types import DATETIME # noqa
+from .types import DateTime # noqa
+from .types import DECIMAL # noqa
+from .types import Enum # noqa
+from .types import FLOAT # noqa
+from .types import Float # noqa
+from .types import INT # noqa
+from .types import INTEGER # noqa
+from .types import Integer # noqa
+from .types import Interval # noqa
+from .types import JSON # noqa
+from .types import LargeBinary # noqa
+from .types import NCHAR # noqa
+from .types import NUMERIC # noqa
+from .types import Numeric # noqa
+from .types import NVARCHAR # noqa
+from .types import PickleType # noqa
+from .types import REAL # noqa
+from .types import SMALLINT # noqa
+from .types import SmallInteger # noqa
+from .types import String # noqa
+from .types import TEXT # noqa
+from .types import Text # noqa
+from .types import TIME # noqa
+from .types import Time # noqa
+from .types import TIMESTAMP # noqa
+from .types import TypeDecorator # noqa
+from .types import Unicode # noqa
+from .types import UnicodeText # noqa
+from .types import VARBINARY # noqa
+from .types import VARCHAR # noqa
+
+from .engine import create_engine # noqa nosort
+from .engine import engine_from_config # noqa nosort
-from .sql import (
- alias,
- all_,
- and_,
- any_,
- asc,
- between,
- bindparam,
- case,
- cast,
- collate,
- column,
- delete,
- desc,
- distinct,
- except_,
- except_all,
- exists,
- extract,
- false,
- func,
- funcfilter,
- insert,
- intersect,
- intersect_all,
- join,
- lateral,
- literal,
- literal_column,
- modifier,
- not_,
- null,
- nullsfirst,
- nullslast,
- or_,
- outerjoin,
- outparam,
- over,
- select,
- subquery,
- table,
- tablesample,
- text,
- true,
- tuple_,
- type_coerce,
- union,
- union_all,
- update,
- within_group,
-)
-
-from .types import (
- ARRAY,
- BIGINT,
- BINARY,
- BLOB,
- BOOLEAN,
- BigInteger,
- Binary,
- Boolean,
- CHAR,
- CLOB,
- DATE,
- DATETIME,
- DECIMAL,
- Date,
- DateTime,
- Enum,
- FLOAT,
- Float,
- INT,
- INTEGER,
- Integer,
- Interval,
- JSON,
- LargeBinary,
- NCHAR,
- NVARCHAR,
- NUMERIC,
- Numeric,
- PickleType,
- REAL,
- SMALLINT,
- SmallInteger,
- String,
- TEXT,
- TIME,
- TIMESTAMP,
- Text,
- Time,
- TypeDecorator,
- Unicode,
- UnicodeText,
- VARBINARY,
- VARCHAR,
-)
-
-
-from .schema import (
- CheckConstraint,
- Column,
- ColumnDefault,
- Constraint,
- DefaultClause,
- FetchedValue,
- ForeignKey,
- ForeignKeyConstraint,
- Index,
- MetaData,
- PassiveDefault,
- PrimaryKeyConstraint,
- Sequence,
- Table,
- ThreadLocalMetaData,
- UniqueConstraint,
- DDL,
- BLANK_SCHEMA,
-)
-
-
-from .inspection import inspect
-from .engine import create_engine, engine_from_config
__version__ = "1.3.0b2"
@@ -136,7 +128,7 @@ __version__ = "1.3.0b2"
def __go(lcls):
global __all__
- from . import events
+ from . import events # noqa
from . import util as _sa_util
import inspect as _inspect
diff --git a/lib/sqlalchemy/connectors/mxodbc.py b/lib/sqlalchemy/connectors/mxodbc.py
index 209877e4a..1cd695269 100644
--- a/lib/sqlalchemy/connectors/mxodbc.py
+++ b/lib/sqlalchemy/connectors/mxodbc.py
@@ -19,8 +19,8 @@ For more info on mxODBC, see http://www.egenix.com/
"""
-import sys
import re
+import sys
import warnings
from . import Connector
@@ -89,7 +89,7 @@ class MxODBCConnector(Connector):
return error_handler
def create_connect_args(self, url):
- """ Return a tuple of *args,**kwargs for creating a connection.
+ r"""Return a tuple of \*args, \**kwargs for creating a connection.
The mxODBC 3.x connection constructor looks like this:
diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py
index 8f5eea89b..6c96661a0 100644
--- a/lib/sqlalchemy/connectors/pyodbc.py
+++ b/lib/sqlalchemy/connectors/pyodbc.py
@@ -5,13 +5,12 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
+import re
+
from . import Connector
from .. import util
-import re
-
-
class PyODBCConnector(Connector):
driver = "pyodbc"
diff --git a/lib/sqlalchemy/connectors/zxJDBC.py b/lib/sqlalchemy/connectors/zxJDBC.py
index 003ecbed1..a017f7d13 100644
--- a/lib/sqlalchemy/connectors/zxJDBC.py
+++ b/lib/sqlalchemy/connectors/zxJDBC.py
@@ -6,6 +6,7 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
import sys
+
from . import Connector
diff --git a/lib/sqlalchemy/databases/__init__.py b/lib/sqlalchemy/databases/__init__.py
index d2d56a7ae..a30e78416 100644
--- a/lib/sqlalchemy/databases/__init__.py
+++ b/lib/sqlalchemy/databases/__init__.py
@@ -9,17 +9,18 @@
compatibility with pre 0.6 versions.
"""
-from ..dialects.sqlite import base as sqlite
-from ..dialects.postgresql import base as postgresql
-
-postgres = postgresql
-from ..dialects.mysql import base as mysql
-from ..dialects.oracle import base as oracle
from ..dialects.firebird import base as firebird
from ..dialects.mssql import base as mssql
+from ..dialects.mysql import base as mysql
+from ..dialects.oracle import base as oracle
+from ..dialects.postgresql import base as postgresql
+from ..dialects.sqlite import base as sqlite
from ..dialects.sybase import base as sybase
+postgres = postgresql
+
+
__all__ = (
"firebird",
"mssql",
diff --git a/lib/sqlalchemy/dialects/__init__.py b/lib/sqlalchemy/dialects/__init__.py
index 65f30bb76..0f11cb0f0 100644
--- a/lib/sqlalchemy/dialects/__init__.py
+++ b/lib/sqlalchemy/dialects/__init__.py
@@ -17,6 +17,7 @@ __all__ = (
from .. import util
+
_translates = {"postgres": "postgresql"}
diff --git a/lib/sqlalchemy/dialects/firebird/__init__.py b/lib/sqlalchemy/dialects/firebird/__init__.py
index 510d62337..b8de5f0d4 100644
--- a/lib/sqlalchemy/dialects/firebird/__init__.py
+++ b/lib/sqlalchemy/dialects/firebird/__init__.py
@@ -5,21 +5,21 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from . import base, kinterbasdb, fdb # noqa
+from sqlalchemy.dialects.firebird.base import BIGINT
+from sqlalchemy.dialects.firebird.base import BLOB
+from sqlalchemy.dialects.firebird.base import CHAR
+from sqlalchemy.dialects.firebird.base import DATE
+from sqlalchemy.dialects.firebird.base import FLOAT
+from sqlalchemy.dialects.firebird.base import NUMERIC
+from sqlalchemy.dialects.firebird.base import SMALLINT
+from sqlalchemy.dialects.firebird.base import TEXT
+from sqlalchemy.dialects.firebird.base import TIME
+from sqlalchemy.dialects.firebird.base import TIMESTAMP
+from sqlalchemy.dialects.firebird.base import VARCHAR
+from . import base # noqa
+from . import fdb # noqa
+from . import kinterbasdb # noqa
-from sqlalchemy.dialects.firebird.base import (
- SMALLINT,
- BIGINT,
- FLOAT,
- DATE,
- TIME,
- TEXT,
- NUMERIC,
- TIMESTAMP,
- VARCHAR,
- CHAR,
- BLOB,
-)
base.dialect = dialect = fdb.dialect
diff --git a/lib/sqlalchemy/dialects/firebird/base.py b/lib/sqlalchemy/dialects/firebird/base.py
index 1e9c778f3..70bec8bd9 100644
--- a/lib/sqlalchemy/dialects/firebird/base.py
+++ b/lib/sqlalchemy/dialects/firebird/base.py
@@ -72,26 +72,26 @@ the SQLAlchemy ``returning()`` method, such as::
import datetime
-from sqlalchemy import schema as sa_schema
-from sqlalchemy import exc, types as sqltypes, sql, util
-from sqlalchemy.sql import expression
-from sqlalchemy.engine import base, default, reflection
+from sqlalchemy import exc
+from sqlalchemy import sql
+from sqlalchemy import types as sqltypes
+from sqlalchemy import util
+from sqlalchemy.engine import default
+from sqlalchemy.engine import reflection
from sqlalchemy.sql import compiler
+from sqlalchemy.sql import expression
from sqlalchemy.sql.elements import quoted_name
-
-from sqlalchemy.types import (
- BIGINT,
- BLOB,
- DATE,
- FLOAT,
- INTEGER,
- NUMERIC,
- SMALLINT,
- TEXT,
- TIME,
- TIMESTAMP,
- Integer,
-)
+from sqlalchemy.types import BIGINT
+from sqlalchemy.types import BLOB
+from sqlalchemy.types import DATE
+from sqlalchemy.types import FLOAT
+from sqlalchemy.types import INTEGER
+from sqlalchemy.types import Integer
+from sqlalchemy.types import NUMERIC
+from sqlalchemy.types import SMALLINT
+from sqlalchemy.types import TEXT
+from sqlalchemy.types import TIME
+from sqlalchemy.types import TIMESTAMP
RESERVED_WORDS = set(
@@ -547,11 +547,11 @@ class FBDDLCompiler(sql.compiler.DDLCompiler):
# no syntax for these
# http://www.firebirdsql.org/manual/generatorguide-sqlsyntax.html
if create.element.start is not None:
- raise NotImplemented(
+ raise NotImplementedError(
"Firebird SEQUENCE doesn't support START WITH"
)
if create.element.increment is not None:
- raise NotImplemented(
+ raise NotImplementedError(
"Firebird SEQUENCE doesn't support INCREMENT BY"
)
@@ -659,9 +659,9 @@ class FBDialect(default.DefaultDialect):
name = name and name.rstrip()
if name is None:
return None
- elif name.upper() == name and not self.identifier_preparer._requires_quotes(
- name.lower()
- ):
+ elif name.upper() == name and not (
+ self.identifier_preparer._requires_quotes
+ )(name.lower()):
return name.lower()
elif name.lower() == name:
return quoted_name(name, quote=True)
@@ -671,9 +671,9 @@ class FBDialect(default.DefaultDialect):
def denormalize_name(self, name):
if name is None:
return None
- elif name.lower() == name and not self.identifier_preparer._requires_quotes(
- name.lower()
- ):
+ elif name.lower() == name and not (
+ self.identifier_preparer._requires_quotes
+ )(name.lower()):
return name.upper()
else:
return name
diff --git a/lib/sqlalchemy/dialects/firebird/fdb.py b/lib/sqlalchemy/dialects/firebird/fdb.py
index 5bf3d2c49..83ca5221b 100644
--- a/lib/sqlalchemy/dialects/firebird/fdb.py
+++ b/lib/sqlalchemy/dialects/firebird/fdb.py
@@ -9,8 +9,7 @@
.. dialect:: firebird+fdb
:name: fdb
:dbapi: pyodbc
- :connectstring: firebird+fdb://user:password@host:port/path/to/db\
-[?key=value&key=value...]
+ :connectstring: firebird+fdb://user:password@host:port/path/to/db[?key=value&key=value...]
:url: http://pypi.python.org/pypi/fdb/
fdb is a kinterbasdb compatible DBAPI for Firebird.
@@ -66,7 +65,7 @@ accept every argument that Kinterbasdb does.
http://pythonhosted.org/fdb/usage-guide.html#retaining-transactions
- information on the "retaining" flag.
-"""
+""" # noqa
from .kinterbasdb import FBDialect_kinterbasdb
from ... import util
diff --git a/lib/sqlalchemy/dialects/firebird/kinterbasdb.py b/lib/sqlalchemy/dialects/firebird/kinterbasdb.py
index 6d7144096..8adce847e 100644
--- a/lib/sqlalchemy/dialects/firebird/kinterbasdb.py
+++ b/lib/sqlalchemy/dialects/firebird/kinterbasdb.py
@@ -9,8 +9,7 @@
.. dialect:: firebird+kinterbasdb
:name: kinterbasdb
:dbapi: kinterbasdb
- :connectstring: firebird+kinterbasdb://user:password@host:port/path/to/db\
-[?key=value&key=value...]
+ :connectstring: firebird+kinterbasdb://user:password@host:port/path/to/db[?key=value&key=value...]
:url: http://firebirdsql.org/index.php?op=devel&sub=python
Arguments
@@ -36,12 +35,15 @@ In addition, it also accepts the following:
http://kinterbasdb.sourceforge.net/dist_docs/usage.html#special_issue_concurrency
-"""
+""" # noqa
-from .base import FBDialect, FBExecutionContext
-from ... import util, types as sqltypes
-from re import match
import decimal
+from re import match
+
+from .base import FBDialect
+from .base import FBExecutionContext
+from ... import types as sqltypes
+from ... import util
class _kinterbasdb_numeric(object):
diff --git a/lib/sqlalchemy/dialects/mssql/__init__.py b/lib/sqlalchemy/dialects/mssql/__init__.py
index 88a94fcfb..5bf822bca 100644
--- a/lib/sqlalchemy/dialects/mssql/__init__.py
+++ b/lib/sqlalchemy/dialects/mssql/__init__.py
@@ -5,41 +5,44 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from . import base, pyodbc, adodbapi, pymssql, zxjdbc, mxodbc # noqa
+from . import adodbapi # noqa
+from . import base # noqa
+from . import mxodbc # noqa
+from . import pymssql # noqa
+from . import pyodbc # noqa
+from . import zxjdbc # noqa
+from .base import BIGINT
+from .base import BINARY
+from .base import BIT
+from .base import CHAR
+from .base import DATE
+from .base import DATETIME
+from .base import DATETIME2
+from .base import DATETIMEOFFSET
+from .base import DECIMAL
+from .base import FLOAT
+from .base import IMAGE
+from .base import INTEGER
+from .base import MONEY
+from .base import NCHAR
+from .base import NTEXT
+from .base import NUMERIC
+from .base import NVARCHAR
+from .base import REAL
+from .base import ROWVERSION
+from .base import SMALLDATETIME
+from .base import SMALLINT
+from .base import SMALLMONEY
+from .base import SQL_VARIANT
+from .base import TEXT
+from .base import TIME
+from .base import TIMESTAMP
+from .base import TINYINT
+from .base import UNIQUEIDENTIFIER
+from .base import VARBINARY
+from .base import VARCHAR
+from .base import XML
-from .base import (
- INTEGER,
- BIGINT,
- SMALLINT,
- TINYINT,
- VARCHAR,
- NVARCHAR,
- CHAR,
- NCHAR,
- TEXT,
- NTEXT,
- DECIMAL,
- NUMERIC,
- FLOAT,
- DATETIME,
- DATETIME2,
- DATETIMEOFFSET,
- DATE,
- TIME,
- SMALLDATETIME,
- BINARY,
- VARBINARY,
- BIT,
- REAL,
- IMAGE,
- TIMESTAMP,
- ROWVERSION,
- MONEY,
- SMALLMONEY,
- UNIQUEIDENTIFIER,
- SQL_VARIANT,
- XML,
-)
base.dialect = dialect = pyodbc.dialect
diff --git a/lib/sqlalchemy/dialects/mssql/adodbapi.py b/lib/sqlalchemy/dialects/mssql/adodbapi.py
index d985c3bb6..08f7ae28a 100644
--- a/lib/sqlalchemy/dialects/mssql/adodbapi.py
+++ b/lib/sqlalchemy/dialects/mssql/adodbapi.py
@@ -19,10 +19,13 @@
"""
import datetime
-from sqlalchemy import types as sqltypes, util
-from sqlalchemy.dialects.mssql.base import MSDateTime, MSDialect
import sys
+from sqlalchemy import types as sqltypes
+from sqlalchemy import util
+from sqlalchemy.dialects.mssql.base import MSDateTime
+from sqlalchemy.dialects.mssql.base import MSDialect
+
class MSDateTime_adodbapi(MSDateTime):
def result_processor(self, dialect, coltype):
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index 161297015..ac427b5fd 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -4,7 +4,6 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-
"""
.. dialect:: mssql
:name: Microsoft SQL Server
@@ -331,9 +330,10 @@ for these types will be issued as DATETIME.
Large Text/Binary Type Deprecation
----------------------------------
-Per `SQL Server 2012/2014 Documentation <http://technet.microsoft.com/en-us/library/ms187993.aspx>`_,
-the ``NTEXT``, ``TEXT`` and ``IMAGE`` datatypes are to be removed from SQL Server
-in a future release. SQLAlchemy normally relates these types to the
+Per
+`SQL Server 2012/2014 Documentation <http://technet.microsoft.com/en-us/library/ms187993.aspx>`_,
+the ``NTEXT``, ``TEXT`` and ``IMAGE`` datatypes are to be removed from SQL
+Server in a future release. SQLAlchemy normally relates these types to the
:class:`.UnicodeText`, :class:`.Text` and :class:`.LargeBinary` datatypes.
In order to accommodate this change, a new flag ``deprecate_large_types``
@@ -355,9 +355,9 @@ behavior of this flag is as follows:
established. If the dialect is used to render DDL without the flag being
set, it is interpreted the same as ``False``.
-* On first connection, the dialect detects if SQL Server version 2012 or greater
- is in use; if the flag is still at ``None``, it sets it to ``True`` or
- ``False`` based on whether 2012 or greater is detected.
+* On first connection, the dialect detects if SQL Server version 2012 or
+ greater is in use; if the flag is still at ``None``, it sets it to ``True``
+ or ``False`` based on whether 2012 or greater is detected.
* The flag can be set to either ``True`` or ``False`` when the dialect
is created, typically via :func:`.create_engine`::
@@ -368,8 +368,8 @@ behavior of this flag is as follows:
* Complete control over whether the "old" or "new" types are rendered is
available in all SQLAlchemy versions by using the UPPERCASE type objects
instead: :class:`.NVARCHAR`, :class:`.VARCHAR`, :class:`.types.VARBINARY`,
- :class:`.TEXT`, :class:`.mssql.NTEXT`, :class:`.mssql.IMAGE` will always remain
- fixed and always output exactly that type.
+ :class:`.TEXT`, :class:`.mssql.NTEXT`, :class:`.mssql.IMAGE` will always
+ remain fixed and always output exactly that type.
.. versionadded:: 1.0.0
@@ -643,38 +643,42 @@ following ALTER DATABASE commands executed at the SQL prompt::
Background on SQL Server snapshot isolation is available at
http://msdn.microsoft.com/en-us/library/ms175095.aspx.
+""" # noqa
-"""
import codecs
import datetime
import operator
import re
-from ... import sql, schema as sa_schema, exc, util
-from ...sql import compiler, expression, util as sql_util, quoted_name
+from . import information_schema as ischema
from ... import engine
-from ...engine import reflection, default
+from ... import exc
+from ... import schema as sa_schema
+from ... import sql
from ... import types as sqltypes
-from ...types import (
- INTEGER,
- BIGINT,
- SMALLINT,
- DECIMAL,
- NUMERIC,
- FLOAT,
- DATETIME,
- DATE,
- BINARY,
- TEXT,
- VARCHAR,
- NVARCHAR,
- CHAR,
- NCHAR,
-)
-
-
+from ... import util
+from ...engine import default
+from ...engine import reflection
+from ...sql import compiler
+from ...sql import expression
+from ...sql import quoted_name
+from ...sql import util as sql_util
+from ...types import BIGINT
+from ...types import BINARY
+from ...types import CHAR
+from ...types import DATE
+from ...types import DATETIME
+from ...types import DECIMAL
+from ...types import FLOAT
+from ...types import INTEGER
+from ...types import NCHAR
+from ...types import NUMERIC
+from ...types import NVARCHAR
+from ...types import SMALLINT
+from ...types import TEXT
+from ...types import VARCHAR
from ...util import update_wrapper
-from . import information_schema as ischema
+
# http://sqlserverbuilds.blogspot.com/
MS_2016_VERSION = (13,)
@@ -1357,9 +1361,9 @@ class MSExecutionContext(default.DefaultExecutionContext):
insert_has_sequence = seq_column is not None
if insert_has_sequence:
- self._enable_identity_insert = seq_column.key in self.compiled_parameters[
- 0
- ] or (
+ self._enable_identity_insert = (
+ seq_column.key in self.compiled_parameters[0]
+ ) or (
self.compiled.statement.parameters
and (
(
@@ -2462,7 +2466,7 @@ class MSDialect(default.DefaultDialect):
break
(
name,
- type,
+ type_,
nullable,
charlen,
numericprec,
@@ -2479,7 +2483,7 @@ class MSDialect(default.DefaultDialect):
row[columns.c.column_default],
row[columns.c.collation_name],
)
- coltype = self.ischema_names.get(type, None)
+ coltype = self.ischema_names.get(type_, None)
kwargs = {}
if coltype in (
@@ -2501,7 +2505,8 @@ class MSDialect(default.DefaultDialect):
if coltype is None:
util.warn(
- "Did not recognize type '%s' of column '%s'" % (type, name)
+ "Did not recognize type '%s' of column '%s'"
+ % (type_, name)
)
coltype = sqltypes.NULLTYPE
else:
diff --git a/lib/sqlalchemy/dialects/mssql/information_schema.py b/lib/sqlalchemy/dialects/mssql/information_schema.py
index c4ea8ab0c..0ff40218e 100644
--- a/lib/sqlalchemy/dialects/mssql/information_schema.py
+++ b/lib/sqlalchemy/dialects/mssql/information_schema.py
@@ -8,12 +8,18 @@
# TODO: should be using the sys. catalog with SQL Server, not information
# schema
-from ... import Table, MetaData, Column
-from ...types import String, Unicode, UnicodeText, Integer, TypeDecorator
from ... import cast
+from ... import Column
+from ... import MetaData
+from ... import Table
from ... import util
-from ...sql import expression
from ...ext.compiler import compiles
+from ...sql import expression
+from ...types import Integer
+from ...types import String
+from ...types import TypeDecorator
+from ...types import Unicode
+
ischema = MetaData()
diff --git a/lib/sqlalchemy/dialects/mssql/mxodbc.py b/lib/sqlalchemy/dialects/mssql/mxodbc.py
index 3b9ea2707..6d81e8e49 100644
--- a/lib/sqlalchemy/dialects/mssql/mxodbc.py
+++ b/lib/sqlalchemy/dialects/mssql/mxodbc.py
@@ -43,17 +43,15 @@ of ``False`` will unconditionally use string-escaped parameters.
"""
+from .base import _MSDate
+from .base import _MSDateTime
+from .base import _MSTime
+from .base import MSDialect
+from .base import VARBINARY
+from .pyodbc import _MSNumeric_pyodbc
+from .pyodbc import MSExecutionContext_pyodbc
from ... import types as sqltypes
from ...connectors.mxodbc import MxODBCConnector
-from .pyodbc import MSExecutionContext_pyodbc, _MSNumeric_pyodbc
-from .base import (
- MSDialect,
- MSSQLStrictCompiler,
- VARBINARY,
- _MSDateTime,
- _MSDate,
- _MSTime,
-)
class _MSNumeric_mxodbc(_MSNumeric_pyodbc):
diff --git a/lib/sqlalchemy/dialects/mssql/pymssql.py b/lib/sqlalchemy/dialects/mssql/pymssql.py
index 847c00329..062c811ba 100644
--- a/lib/sqlalchemy/dialects/mssql/pymssql.py
+++ b/lib/sqlalchemy/dialects/mssql/pymssql.py
@@ -9,8 +9,7 @@
.. dialect:: mssql+pymssql
:name: pymssql
:dbapi: pymssql
- :connectstring: mssql+pymssql://<username>:<password>@<freetds_name>/?\
-charset=utf8
+ :connectstring: mssql+pymssql://<username>:<password>@<freetds_name>/?charset=utf8
:url: http://pymssql.org/
pymssql is a Python module that provides a Python DBAPI interface around
@@ -20,11 +19,15 @@ Linux, MacOSX and Windows platforms.
Modern versions of this driver work very well with SQL Server and
FreeTDS from Linux and is highly recommended.
-"""
-from .base import MSDialect, MSIdentifierPreparer
-from ... import types as sqltypes, util, processors
+""" # noqa
import re
+from .base import MSDialect
+from .base import MSIdentifierPreparer
+from ... import processors
+from ... import types as sqltypes
+from ... import util
+
class _MSNumeric_pymssql(sqltypes.Numeric):
def result_processor(self, dialect, type_):
diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py
index db5573c2c..c2d475b10 100644
--- a/lib/sqlalchemy/dialects/mssql/pyodbc.py
+++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py
@@ -55,8 +55,8 @@ Pass through exact Pyodbc string
A PyODBC connection string can also be sent exactly as specified in
`ConnectionStrings <https://code.google.com/p/pyodbc/wiki/ConnectionStrings>`_
-into the driver using the parameter ``odbc_connect``. The delimeters must be URL escaped, however,
-as illustrated below using ``urllib.quote_plus``::
+into the driver using the parameter ``odbc_connect``. The delimeters must be
+URL escaped, however, as illustrated below using ``urllib.quote_plus``::
import urllib
params = urllib.quote_plus("DRIVER={SQL Server Native Client 10.0};SERVER=dagger;DATABASE=test;UID=user;PWD=password")
@@ -107,19 +107,24 @@ in order to use this flag::
.. seealso::
- `fast executemany
- <https://github.com/mkleehammer/pyodbc/wiki/Features-beyond-the-DB-API#fast_executemany>`_
+ `fast executemany <https://github.com/mkleehammer/pyodbc/wiki/Features-beyond-the-DB-API#fast_executemany>`_
- on github
-"""
+""" # noqa
-from .base import MSExecutionContext, MSDialect, BINARY, VARBINARY
-from ...connectors.pyodbc import PyODBCConnector
-from ... import types as sqltypes, util, exc
import decimal
import re
+from .base import BINARY
+from .base import MSDialect
+from .base import MSExecutionContext
+from .base import VARBINARY
+from ... import exc
+from ... import types as sqltypes
+from ... import util
+from ...connectors.pyodbc import PyODBCConnector
+
class _ms_numeric_pyodbc(object):
diff --git a/lib/sqlalchemy/dialects/mssql/zxjdbc.py b/lib/sqlalchemy/dialects/mssql/zxjdbc.py
index 13fc46e19..8ef74f2d8 100644
--- a/lib/sqlalchemy/dialects/mssql/zxjdbc.py
+++ b/lib/sqlalchemy/dialects/mssql/zxjdbc.py
@@ -9,17 +9,17 @@
.. dialect:: mssql+zxjdbc
:name: zxJDBC for Jython
:dbapi: zxjdbc
- :connectstring: mssql+zxjdbc://user:pass@host:port/dbname\
-[?key=value&key=value...]
+ :connectstring: mssql+zxjdbc://user:pass@host:port/dbname[?key=value&key=value...]
:driverurl: http://jtds.sourceforge.net/
.. note:: Jython is not supported by current versions of SQLAlchemy. The
zxjdbc dialect should be considered as experimental.
-"""
-from ...connectors.zxJDBC import ZxJDBCConnector
-from .base import MSDialect, MSExecutionContext
+""" # noqa
+from .base import MSDialect
+from .base import MSExecutionContext
from ... import engine
+from ...connectors.zxJDBC import ZxJDBCConnector
class MSExecutionContext_zxjdbc(MSExecutionContext):
diff --git a/lib/sqlalchemy/dialects/mysql/__init__.py b/lib/sqlalchemy/dialects/mysql/__init__.py
index ffeb8f486..65a30a5b2 100644
--- a/lib/sqlalchemy/dialects/mysql/__init__.py
+++ b/lib/sqlalchemy/dialects/mysql/__init__.py
@@ -5,58 +5,52 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from . import (
- base,
- mysqldb,
- oursql,
- pyodbc,
- zxjdbc,
- mysqlconnector,
- pymysql,
- gaerdbms,
- cymysql,
-)
-
-from .base import (
- BIGINT,
- BINARY,
- BIT,
- BLOB,
- BOOLEAN,
- CHAR,
- DATE,
- DATETIME,
- DECIMAL,
- DOUBLE,
- ENUM,
- DECIMAL,
- FLOAT,
- INTEGER,
- INTEGER,
- JSON,
- LONGBLOB,
- LONGTEXT,
- MEDIUMBLOB,
- MEDIUMINT,
- MEDIUMTEXT,
- NCHAR,
- NVARCHAR,
- NUMERIC,
- SET,
- SMALLINT,
- REAL,
- TEXT,
- TIME,
- TIMESTAMP,
- TINYBLOB,
- TINYINT,
- TINYTEXT,
- VARBINARY,
- VARCHAR,
- YEAR,
-)
+from . import base # noqa
+from . import cymysql # noqa
+from . import gaerdbms # noqa
+from . import mysqlconnector # noqa
+from . import mysqldb # noqa
+from . import oursql # noqa
+from . import pymysql # noqa
+from . import pyodbc # noqa
+from . import zxjdbc # noqa
+from .base import BIGINT
+from .base import BINARY
+from .base import BIT
+from .base import BLOB
+from .base import BOOLEAN
+from .base import CHAR
+from .base import DATE
+from .base import DATETIME
+from .base import DECIMAL
+from .base import DOUBLE
+from .base import ENUM
+from .base import FLOAT
+from .base import INTEGER
+from .base import JSON
+from .base import LONGBLOB
+from .base import LONGTEXT
+from .base import MEDIUMBLOB
+from .base import MEDIUMINT
+from .base import MEDIUMTEXT
+from .base import NCHAR
+from .base import NUMERIC
+from .base import NVARCHAR
+from .base import REAL
+from .base import SET
+from .base import SMALLINT
+from .base import TEXT
+from .base import TIME
+from .base import TIMESTAMP
+from .base import TINYBLOB
+from .base import TINYINT
+from .base import TINYTEXT
+from .base import VARBINARY
+from .base import VARCHAR
+from .base import YEAR
+from .dml import Insert
+from .dml import insert
-from .dml import insert, Insert
# default dialect
base.dialect = dialect = mysqldb.dialect
@@ -100,4 +94,6 @@ __all__ = (
"VARCHAR",
"YEAR",
"dialect",
+ "insert",
+ "Insert",
)
diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py
index 7b0d0618c..4a0d82fe1 100644
--- a/lib/sqlalchemy/dialects/mysql/base.py
+++ b/lib/sqlalchemy/dialects/mysql/base.py
@@ -118,14 +118,13 @@ to be used.
Transaction Isolation Level
---------------------------
-All MySQL dialects support setting of transaction isolation level
-both via a dialect-specific parameter :paramref:`.create_engine.isolation_level`
-accepted by :func:`.create_engine`,
-as well as the :paramref:`.Connection.execution_options.isolation_level`
-argument as passed to :meth:`.Connection.execution_options`.
-This feature works by issuing the command
-``SET SESSION TRANSACTION ISOLATION LEVEL <level>`` for
-each new connection. For the special AUTOCOMMIT isolation level, DBAPI-specific
+All MySQL dialects support setting of transaction isolation level both via a
+dialect-specific parameter :paramref:`.create_engine.isolation_level` accepted
+by :func:`.create_engine`, as well as the
+:paramref:`.Connection.execution_options.isolation_level` argument as passed to
+:meth:`.Connection.execution_options`. This feature works by issuing the
+command ``SET SESSION TRANSACTION ISOLATION LEVEL <level>`` for each new
+connection. For the special AUTOCOMMIT isolation level, DBAPI-specific
techniques are used.
To set isolation level using :func:`.create_engine`::
@@ -258,31 +257,35 @@ emit a warning when attempting to pass binary data to the database, while a
character set encoding is also in place, when the binary data itself is not
valid for that encoding::
- default.py:509: Warning: (1300, "Invalid utf8mb4 character string: 'F9876A'")
+ default.py:509: Warning: (1300, "Invalid utf8mb4 character string:
+ 'F9876A'")
cursor.execute(statement, parameters)
This warning is due to the fact that the MySQL client library is attempting to
-interpret the binary string as a unicode object even if a datatype such as
-:class:`.LargeBinary` is in use. To resolve this, the SQL statement requires
+interpret the binary string as a unicode object even if a datatype such
+as :class:`.LargeBinary` is in use. To resolve this, the SQL statement requires
a binary "character set introducer" be present before any non-NULL value
that renders like this::
INSERT INTO table (data) VALUES (_binary %s)
-These character set introducers are provided by the DBAPI driver, assuming
-the use of mysqlclient or PyMySQL (both of which are recommended). Add the
-query string parameter ``binary_prefix=true`` to the URL to repair this warning::
+These character set introducers are provided by the DBAPI driver, assuming the
+use of mysqlclient or PyMySQL (both of which are recommended). Add the query
+string parameter ``binary_prefix=true`` to the URL to repair this warning::
# mysqlclient
- engine = create_engine("mysql+mysqldb://scott:tiger@localhost/test?charset=utf8mb4&binary_prefix=true")
+ engine = create_engine(
+ "mysql+mysqldb://scott:tiger@localhost/test?charset=utf8mb4&binary_prefix=true")
# PyMySQL
- engine = create_engine("mysql+pymysql://scott:tiger@localhost/test?charset=utf8mb4&binary_prefix=true")
+ engine = create_engine(
+ "mysql+pymysql://scott:tiger@localhost/test?charset=utf8mb4&binary_prefix=true")
+
The ``binary_prefix`` flag may or may not be supported by other MySQL drivers.
-SQLAlchemy itself cannot render this ``_binary`` prefix reliably, as it does not
-work with the NULL value, which is valid to be sent as a bound parameter.
+SQLAlchemy itself cannot render this ``_binary`` prefix reliably, as it does
+not work with the NULL value, which is valid to be sent as a bound parameter.
As the MySQL driver renders parameters directly into the SQL string, it's the
most efficient place for this additional keyword to be passed.
@@ -320,7 +323,8 @@ And of course any valid MySQL statement can be executed as a string as well.
Some limited direct support for MySQL extensions to SQL is currently
available.
-* INSERT..ON DUPLICATE KEY UPDATE: See :ref:`mysql_insert_on_duplicate_key_update`
+* INSERT..ON DUPLICATE KEY UPDATE: See
+ :ref:`mysql_insert_on_duplicate_key_update`
* SELECT pragma::
@@ -530,8 +534,7 @@ storage engine.
.. seealso::
- `CREATE INDEX <http://dev.mysql.com/doc/refman/5.0/en/create-index.html>`_ - \
- MySQL documentation
+ `CREATE INDEX <http://dev.mysql.com/doc/refman/5.0/en/create-index.html>`_ - MySQL documentation
Index Types
~~~~~~~~~~~~~
@@ -696,8 +699,8 @@ any other datatype on the MySQL side with regards to defaults and nullability.
However, to accommodate the vast majority of MySQL databases that do not
specify this new flag, SQLAlchemy emits the "NULL" specifier explicitly with
-any TIMESTAMP column that does not specify ``nullable=False``. In order
-to accommodate newer databases that specify ``explicit_defaults_for_timestamp``,
+any TIMESTAMP column that does not specify ``nullable=False``. In order to
+accommodate newer databases that specify ``explicit_defaults_for_timestamp``,
SQLAlchemy also emits NOT NULL for TIMESTAMP columns that do specify
``nullable=False``. The following example illustrates::
@@ -731,61 +734,66 @@ output::
``explicit_defaults_for_timestamp``. Prior to this version, it will
not render "NOT NULL" for a TIMESTAMP column that is ``nullable=False``.
-"""
+""" # noqa
+from array import array as _array
from collections import defaultdict
import re
import sys
+from . import reflection as _reflection
+from .enumerated import ENUM
+from .enumerated import SET
+from .json import JSON
+from .json import JSONIndexType
+from .json import JSONPathType
+from .types import _FloatType
+from .types import _IntegerType
+from .types import _MatchType
+from .types import _NumericType
+from .types import _StringType
+from .types import BIGINT
+from .types import BIT
+from .types import CHAR
+from .types import DATETIME
+from .types import DECIMAL
+from .types import DOUBLE
+from .types import FLOAT
+from .types import INTEGER
+from .types import LONGBLOB
+from .types import LONGTEXT
+from .types import MEDIUMBLOB
+from .types import MEDIUMINT
+from .types import MEDIUMTEXT
+from .types import NCHAR
+from .types import NUMERIC
+from .types import NVARCHAR
+from .types import REAL
+from .types import SMALLINT
+from .types import TEXT
+from .types import TIME
+from .types import TIMESTAMP
+from .types import TINYBLOB
+from .types import TINYINT
+from .types import TINYTEXT
+from .types import VARCHAR
+from .types import YEAR
+from ... import exc
+from ... import log
from ... import schema as sa_schema
-from ... import exc, log, sql, util
-from ...sql import compiler, elements
-from array import array as _array
-
-from ...engine import reflection
-from ...engine import default
+from ... import sql
from ... import types as sqltypes
+from ... import util
+from ...engine import default
+from ...engine import reflection
+from ...sql import compiler
+from ...sql import elements
+from ...types import BINARY
+from ...types import BLOB
+from ...types import BOOLEAN
+from ...types import DATE
+from ...types import VARBINARY
from ...util import topological
-from ...types import DATE, BOOLEAN, BLOB, BINARY, VARBINARY
-
-from . import reflection as _reflection
-from .types import (
- BIGINT,
- BIT,
- CHAR,
- DECIMAL,
- DATETIME,
- DOUBLE,
- FLOAT,
- INTEGER,
- LONGBLOB,
- LONGTEXT,
- MEDIUMBLOB,
- MEDIUMINT,
- MEDIUMTEXT,
- NCHAR,
- NUMERIC,
- NVARCHAR,
- REAL,
- SMALLINT,
- TEXT,
- TIME,
- TIMESTAMP,
- TINYBLOB,
- TINYINT,
- TINYTEXT,
- VARCHAR,
- YEAR,
-)
-from .types import (
- _StringType,
- _IntegerType,
- _NumericType,
- _FloatType,
- _MatchType,
-)
-from .enumerated import ENUM, SET
-from .json import JSON, JSONIndexType, JSONPathType
RESERVED_WORDS = set(
@@ -2026,7 +2034,7 @@ class MySQLTypeCompiler(compiler.GenericTypeCompiler):
"SET", type_, type_._enumerated_values
)
- def visit_BOOLEAN(self, type, **kw):
+ def visit_BOOLEAN(self, type_, **kw):
return "BOOL"
diff --git a/lib/sqlalchemy/dialects/mysql/cymysql.py b/lib/sqlalchemy/dialects/mysql/cymysql.py
index 8a60608db..ba7c6fac2 100644
--- a/lib/sqlalchemy/dialects/mysql/cymysql.py
+++ b/lib/sqlalchemy/dialects/mysql/cymysql.py
@@ -4,21 +4,19 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-
-"""
+r"""
.. dialect:: mysql+cymysql
:name: CyMySQL
:dbapi: cymysql
- :connectstring: mysql+cymysql://<username>:<password>@<host>/<dbname>\
-[?<options>]
+ :connectstring: mysql+cymysql://<username>:<password>@<host>/<dbname>[?<options>]
:url: https://github.com/nakagami/CyMySQL
-"""
-import re
+""" # noqa
+from .base import BIT
+from .base import MySQLDialect
from .mysqldb import MySQLDialect_mysqldb
-from .base import BIT, MySQLDialect
from ... import util
diff --git a/lib/sqlalchemy/dialects/mysql/dml.py b/lib/sqlalchemy/dialects/mysql/dml.py
index 5d59b2073..59cd22d36 100644
--- a/lib/sqlalchemy/dialects/mysql/dml.py
+++ b/lib/sqlalchemy/dialects/mysql/dml.py
@@ -1,10 +1,11 @@
-from ...sql.elements import ClauseElement
+from ... import exc
+from ... import util
+from ...sql.base import _generative
from ...sql.dml import Insert as StandardInsert
+from ...sql.elements import ClauseElement
from ...sql.expression import alias
from ...util.langhelpers import public_factory
-from ...sql.base import _generative
-from ... import exc
-from ... import util
+
__all__ = ("Insert", "insert")
diff --git a/lib/sqlalchemy/dialects/mysql/enumerated.py b/lib/sqlalchemy/dialects/mysql/enumerated.py
index 9586eff3f..fe42bb3aa 100644
--- a/lib/sqlalchemy/dialects/mysql/enumerated.py
+++ b/lib/sqlalchemy/dialects/mysql/enumerated.py
@@ -8,7 +8,9 @@
import re
from .types import _StringType
-from ... import exc, sql, util
+from ... import exc
+from ... import sql
+from ... import util
from ...sql import sqltypes
diff --git a/lib/sqlalchemy/dialects/mysql/gaerdbms.py b/lib/sqlalchemy/dialects/mysql/gaerdbms.py
index 117cd28a2..23c84ec15 100644
--- a/lib/sqlalchemy/dialects/mysql/gaerdbms.py
+++ b/lib/sqlalchemy/dialects/mysql/gaerdbms.py
@@ -4,13 +4,12 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""
+r"""
.. dialect:: mysql+gaerdbms
:name: Google Cloud SQL
:dbapi: rdbms
:connectstring: mysql+gaerdbms:///<dbname>?instance=<instancename>
- :url: https://developers.google.com/appengine/docs/python/cloud-sql/\
-developers-guide
+ :url: https://developers.google.com/appengine/docs/python/cloud-sql/developers-guide
This dialect is based primarily on the :mod:`.mysql.mysqldb` dialect with
minimal changes.
@@ -33,14 +32,14 @@ so the dialect does not pool connections. The :class:`.NullPool`
implementation is installed within the :class:`.Engine` by
default.
-"""
+""" # noqa
import os
+import re
+from sqlalchemy.util import warn_deprecated
from .mysqldb import MySQLDialect_mysqldb
from ...pool import NullPool
-import re
-from sqlalchemy.util import warn_deprecated
def _is_dev_environment():
diff --git a/lib/sqlalchemy/dialects/mysql/json.py b/lib/sqlalchemy/dialects/mysql/json.py
index 162d48f73..0f2ca439f 100644
--- a/lib/sqlalchemy/dialects/mysql/json.py
+++ b/lib/sqlalchemy/dialects/mysql/json.py
@@ -7,9 +7,7 @@
from __future__ import absolute_import
-from ...sql import elements
from ... import types as sqltypes
-from ... import util
class JSON(sqltypes.JSON):
diff --git a/lib/sqlalchemy/dialects/mysql/mysqlconnector.py b/lib/sqlalchemy/dialects/mysql/mysqlconnector.py
index 9c1502a14..3e2211060 100644
--- a/lib/sqlalchemy/dialects/mysql/mysqlconnector.py
+++ b/lib/sqlalchemy/dialects/mysql/mysqlconnector.py
@@ -5,12 +5,11 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""
+r"""
.. dialect:: mysql+mysqlconnector
:name: MySQL Connector/Python
:dbapi: myconnpy
- :connectstring: mysql+mysqlconnector://<user>:<password>@\
-<host>[:<port>]/<dbname>
+ :connectstring: mysql+mysqlconnector://<user>:<password>@<host>[:<port>]/<dbname>
:url: http://dev.mysql.com/downloads/connector/python/
@@ -45,19 +44,17 @@ This list should be updated as these issues are resolved either in the
upstream mysql-connector-python driver or if appropriate usage patterns
are contributed to SQLAlchemy.
-"""
+""" # noqa
-from .base import (
- MySQLDialect,
- MySQLExecutionContext,
- MySQLCompiler,
- MySQLIdentifierPreparer,
- BIT,
-)
-
-from ... import util
import re
+
+from .base import BIT
+from .base import MySQLCompiler
+from .base import MySQLDialect
+from .base import MySQLExecutionContext
+from .base import MySQLIdentifierPreparer
from ... import processors
+from ... import util
class MySQLExecutionContext_mysqlconnector(MySQLExecutionContext):
@@ -140,9 +137,9 @@ class MySQLDialect_mysqlconnector(MySQLDialect):
# hack description encoding since mysqlconnector randomly
# returns bytes or not
- self._description_decoder = processors.to_conditional_unicode_processor_factory(
- self.description_encoding
- )
+ self._description_decoder = (
+ processors.to_conditional_unicode_processor_factory
+ )(self.description_encoding)
def _check_unicode_description(self, connection):
# hack description encoding since mysqlconnector randomly
diff --git a/lib/sqlalchemy/dialects/mysql/mysqldb.py b/lib/sqlalchemy/dialects/mysql/mysqldb.py
index 6d42f5c04..313940cbc 100644
--- a/lib/sqlalchemy/dialects/mysql/mysqldb.py
+++ b/lib/sqlalchemy/dialects/mysql/mysqldb.py
@@ -45,16 +45,15 @@ The mysqldb dialect supports server-side cursors. See :ref:`mysql_ss_cursors`.
"""
-from .base import (
- MySQLDialect,
- MySQLExecutionContext,
- MySQLCompiler,
- MySQLIdentifierPreparer,
-)
+import re
+
+from .base import MySQLCompiler
+from .base import MySQLDialect
+from .base import MySQLExecutionContext
+from .base import MySQLIdentifierPreparer
from .base import TEXT
from ... import sql
from ... import util
-import re
class MySQLExecutionContext_mysqldb(MySQLExecutionContext):
diff --git a/lib/sqlalchemy/dialects/mysql/oursql.py b/lib/sqlalchemy/dialects/mysql/oursql.py
index 8ba353a31..560135a40 100644
--- a/lib/sqlalchemy/dialects/mysql/oursql.py
+++ b/lib/sqlalchemy/dialects/mysql/oursql.py
@@ -22,10 +22,12 @@ handling.
"""
-import re
-from .base import BIT, MySQLDialect, MySQLExecutionContext
-from ... import types as sqltypes, util
+from .base import BIT
+from .base import MySQLDialect
+from .base import MySQLExecutionContext
+from ... import types as sqltypes
+from ... import util
class _oursqlBIT(BIT):
diff --git a/lib/sqlalchemy/dialects/mysql/pymysql.py b/lib/sqlalchemy/dialects/mysql/pymysql.py
index 94dbfff06..2778a9b2f 100644
--- a/lib/sqlalchemy/dialects/mysql/pymysql.py
+++ b/lib/sqlalchemy/dialects/mysql/pymysql.py
@@ -5,13 +5,12 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""
+r"""
.. dialect:: mysql+pymysql
:name: PyMySQL
:dbapi: pymysql
- :connectstring: mysql+pymysql://<username>:<password>@<host>/<dbname>\
-[?<options>]
+ :connectstring: mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]
:url: https://pymysql.readthedocs.io/
Unicode
@@ -27,10 +26,11 @@ The pymysql DBAPI is a pure Python port of the MySQL-python (MySQLdb) driver,
and targets 100% compatibility. Most behavioral notes for MySQL-python apply
to the pymysql driver as well.
-"""
+""" # noqa
from .mysqldb import MySQLDialect_mysqldb
-from ...util import langhelpers, py3k
+from ...util import langhelpers
+from ...util import py3k
class MySQLDialect_pymysql(MySQLDialect_mysqldb):
diff --git a/lib/sqlalchemy/dialects/mysql/pyodbc.py b/lib/sqlalchemy/dialects/mysql/pyodbc.py
index 91512857e..736de5f04 100644
--- a/lib/sqlalchemy/dialects/mysql/pyodbc.py
+++ b/lib/sqlalchemy/dialects/mysql/pyodbc.py
@@ -22,11 +22,13 @@
"""
-from .base import MySQLDialect, MySQLExecutionContext
-from ...connectors.pyodbc import PyODBCConnector
-from ... import util
import re
+from .base import MySQLDialect
+from .base import MySQLExecutionContext
+from ... import util
+from ...connectors.pyodbc import PyODBCConnector
+
class MySQLExecutionContext_pyodbc(MySQLExecutionContext):
def get_lastrowid(self):
diff --git a/lib/sqlalchemy/dialects/mysql/reflection.py b/lib/sqlalchemy/dialects/mysql/reflection.py
index d0513eb4d..87438f460 100644
--- a/lib/sqlalchemy/dialects/mysql/reflection.py
+++ b/lib/sqlalchemy/dialects/mysql/reflection.py
@@ -6,10 +6,15 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
import re
-from ... import log, util
+
+from .enumerated import _EnumeratedValues
+from .enumerated import SET
+from .types import DATETIME
+from .types import TIME
+from .types import TIMESTAMP
+from ... import log
from ... import types as sqltypes
-from .enumerated import _EnumeratedValues, SET
-from .types import DATETIME, TIME, TIMESTAMP
+from ... import util
class ReflectedState(object):
diff --git a/lib/sqlalchemy/dialects/mysql/types.py b/lib/sqlalchemy/dialects/mysql/types.py
index ad97a9bbe..a234ddf08 100644
--- a/lib/sqlalchemy/dialects/mysql/types.py
+++ b/lib/sqlalchemy/dialects/mysql/types.py
@@ -6,8 +6,10 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
import datetime
-from ... import exc, util
+
+from ... import exc
from ... import types as sqltypes
+from ... import util
class _NumericType(object):
@@ -68,7 +70,7 @@ class _StringType(sqltypes.String):
self,
charset=None,
collation=None,
- ascii=False,
+ ascii=False, # noqa
binary=False,
unicode=False,
national=False,
diff --git a/lib/sqlalchemy/dialects/mysql/zxjdbc.py b/lib/sqlalchemy/dialects/mysql/zxjdbc.py
index d8ee43748..3a4cee726 100644
--- a/lib/sqlalchemy/dialects/mysql/zxjdbc.py
+++ b/lib/sqlalchemy/dialects/mysql/zxjdbc.py
@@ -5,13 +5,12 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""
+r"""
.. dialect:: mysql+zxjdbc
:name: zxjdbc for Jython
:dbapi: zxjdbc
- :connectstring: mysql+zxjdbc://<user>:<password>@<hostname>[:<port>]/\
-<database>
+ :connectstring: mysql+zxjdbc://<user>:<password>@<hostname>[:<port>]/<database>
:driverurl: http://dev.mysql.com/downloads/connector/j/
.. note:: Jython is not supported by current versions of SQLAlchemy. The
@@ -26,12 +25,15 @@ MySQL Connector/J JDBC driver, by default SQLAlchemy sets its
``characterEncoding`` connection property to ``UTF-8``. It may be
overridden via a ``create_engine`` URL parameter.
-"""
+""" # noqa
import re
-from ... import types as sqltypes, util
+from .base import BIT
+from .base import MySQLDialect
+from .base import MySQLExecutionContext
+from ... import types as sqltypes
+from ... import util
from ...connectors.zxJDBC import ZxJDBCConnector
-from .base import BIT, MySQLDialect, MySQLExecutionContext
class _ZxJDBCBit(BIT):
diff --git a/lib/sqlalchemy/dialects/oracle/__init__.py b/lib/sqlalchemy/dialects/oracle/__init__.py
index 1b9007fcc..7622bdf19 100644
--- a/lib/sqlalchemy/dialects/oracle/__init__.py
+++ b/lib/sqlalchemy/dialects/oracle/__init__.py
@@ -5,30 +5,30 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from . import base, cx_oracle, zxjdbc # noqa
+from . import base # noqa
+from . import cx_oracle # noqa
+from . import zxjdbc # noqa
+from .base import BFILE
+from .base import BINARY_DOUBLE
+from .base import BINARY_FLOAT
+from .base import BLOB
+from .base import CHAR
+from .base import CLOB
+from .base import DATE
+from .base import DOUBLE_PRECISION
+from .base import FLOAT
+from .base import INTERVAL
+from .base import LONG
+from .base import NCLOB
+from .base import NUMBER
+from .base import NVARCHAR
+from .base import NVARCHAR2
+from .base import RAW
+from .base import ROWID
+from .base import TIMESTAMP
+from .base import VARCHAR
+from .base import VARCHAR2
-from .base import (
- VARCHAR,
- NVARCHAR,
- CHAR,
- DATE,
- NUMBER,
- BLOB,
- BFILE,
- BINARY_FLOAT,
- BINARY_DOUBLE,
- CLOB,
- NCLOB,
- TIMESTAMP,
- RAW,
- FLOAT,
- DOUBLE_PRECISION,
- LONG,
- INTERVAL,
- VARCHAR2,
- NVARCHAR2,
- ROWID,
-)
base.dialect = dialect = cx_oracle.dialect
diff --git a/lib/sqlalchemy/dialects/oracle/base.py b/lib/sqlalchemy/dialects/oracle/base.py
index 944fe21c3..b58d038cf 100644
--- a/lib/sqlalchemy/dialects/oracle/base.py
+++ b/lib/sqlalchemy/dialects/oracle/base.py
@@ -5,7 +5,7 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""
+r"""
.. dialect:: oracle
:name: Oracle
@@ -343,27 +343,31 @@ columns for non-unique indexes, all but the last column for unique indexes).
.. versionadded:: 1.0.0
-"""
+""" # noqa
+from itertools import groupby
import re
-from sqlalchemy import util, sql
-from sqlalchemy.engine import default, reflection
-from sqlalchemy.sql import compiler, visitors, expression, util as sql_util
-from sqlalchemy.sql import operators as sql_operators
-from sqlalchemy.sql.elements import quoted_name
-from sqlalchemy import types as sqltypes, schema as sa_schema
-from sqlalchemy.types import (
- VARCHAR,
- NVARCHAR,
- CHAR,
- BLOB,
- CLOB,
- TIMESTAMP,
- FLOAT,
- INTEGER,
-)
-from itertools import groupby
+from ... import schema as sa_schema
+from ... import sql
+from ... import types as sqltypes
+from ... import util
+from ...engine import default
+from ...engine import reflection
+from ...sql import compiler
+from ...sql import expression
+from ...sql import util as sql_util
+from ...sql import visitors
+from ...sql.elements import quoted_name
+from ...types import BLOB
+from ...types import CHAR
+from ...types import CLOB
+from ...types import FLOAT
+from ...types import INTEGER
+from ...types import NVARCHAR
+from ...types import TIMESTAMP
+from ...types import VARCHAR
+
RESERVED_WORDS = set(
"SHARE RAW DROP BETWEEN FROM DESC OPTION PRIOR LONG THEN "
@@ -1200,9 +1204,9 @@ class OracleDialect(default.DefaultDialect):
if util.py2k:
if isinstance(name, str):
name = name.decode(self.encoding)
- if name.upper() == name and not self.identifier_preparer._requires_quotes(
- name.lower()
- ):
+ if name.upper() == name and not (
+ self.identifier_preparer._requires_quotes
+ )(name.lower()):
return name.lower()
elif name.lower() == name:
return quoted_name(name, quote=True)
@@ -1212,15 +1216,15 @@ class OracleDialect(default.DefaultDialect):
def denormalize_name(self, name):
if name is None:
return None
- elif name.lower() == name and not self.identifier_preparer._requires_quotes(
- name.lower()
- ):
+ elif name.lower() == name and not (
+ self.identifier_preparer._requires_quotes
+ )(name.lower()):
name = name.upper()
if util.py2k:
if not self.supports_unicode_binds:
name = name.encode(self.encoding)
else:
- name = unicode(name)
+ name = unicode(name) # noqa
return name
def _get_default_schema_name(self, connection):
@@ -1827,7 +1831,12 @@ class OracleDialect(default.DefaultDialect):
if not rec["referred_table"]:
if resolve_synonyms:
- ref_remote_name, ref_remote_owner, ref_dblink, ref_synonym = self._resolve_synonym(
+ (
+ ref_remote_name,
+ ref_remote_owner,
+ ref_dblink,
+ ref_synonym,
+ ) = self._resolve_synonym(
connection,
desired_owner=self.denormalize_name(remote_owner),
desired_table=self.denormalize_name(remote_table),
@@ -1882,14 +1891,10 @@ class OracleDialect(default.DefaultDialect):
unique_keys = filter(lambda x: x[1] == "U", constraint_data)
uniques_group = groupby(unique_keys, lambda x: x[0])
- index_names = set(
- [
- ix["name"]
- for ix in self.get_indexes(
- connection, table_name, schema=schema
- )
- ]
- )
+ index_names = {
+ ix["name"]
+ for ix in self.get_indexes(connection, table_name, schema=schema)
+ }
return [
{
"name": name,
diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py
index 91534c0da..ba52176a0 100644
--- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py
+++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py
@@ -4,13 +4,11 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""
-
+r"""
.. dialect:: oracle+cx_oracle
:name: cx-Oracle
:dbapi: cx_oracle
- :connectstring: oracle+cx_oracle://user:pass@host:port/dbname\
-[?key=value&key=value...]
+ :connectstring: oracle+cx_oracle://user:pass@host:port/dbname[?key=value&key=value...]
:url: http://cx-oracle.sourceforge.net/
Additional Connect Arguments
@@ -51,7 +49,8 @@ Alternatively, most cx_Oracle DBAPI arguments can also be encoded as strings
within the URL, which includes parameters such as ``mode``, ``purity``,
``events``, ``threaded``, and others::
- e = create_engine("oracle+cx_oracle://user:pass@dsn?mode=SYSDBA&events=true")
+ e = create_engine(
+ "oracle+cx_oracle://user:pass@dsn?mode=SYSDBA&events=true")
.. versionchanged:: 1.3 the cx_oracle dialect now accepts all argument names
within the URL string itself, to be passed to the cx_Oracle DBAPI. As
@@ -63,7 +62,8 @@ There are also options that are consumed by the SQLAlchemy cx_oracle dialect
itself. These options are always passed directly to :func:`.create_engine`,
such as::
- e = create_engine("oracle+cx_oracle://user:pass@dsn", coerce_to_unicode=False)
+ e = create_engine(
+ "oracle+cx_oracle://user:pass@dsn", coerce_to_unicode=False)
The parameters accepted by the cx_oracle dialect are as follows:
@@ -126,8 +126,8 @@ VARCHAR2, CHAR, and CLOB, the flag ``coerce_to_unicode=False`` can be passed to
.. _cx_oracle_setinputsizes:
-Fine grained control over cx_Oracle data binding and performance with setinputsizes
------------------------------------------------------------------------------------
+Fine grained control over cx_Oracle data binding performance with setinputsizes
+-------------------------------------------------------------------------------
The cx_Oracle DBAPI has a deep and fundamental reliance upon the usage of the
DBAPI ``setinputsizes()`` call. The purpose of this call is to establish the
@@ -140,13 +140,14 @@ settings can cause profoundly different performance characteristics, while
altering the type coercion behavior at the same time.
Users of the cx_Oracle dialect are **strongly encouraged** to read through
-cx_Oracle's list of built-in datatype symbols at http://cx-oracle.readthedocs.io/en/latest/module.html#types.
-Note that in some cases, signficant performance degradation can occur when using
-these types vs. not, in particular when specifying ``cx_Oracle.CLOB``.
-
-On the SQLAlchemy side, the :meth:`.DialectEvents.do_setinputsizes` event
-can be used both for runtime visibliity (e.g. logging) of the setinputsizes
-step as well as to fully control how ``setinputsizes()`` is used on a per-statement
+cx_Oracle's list of built-in datatype symbols at
+http://cx-oracle.readthedocs.io/en/latest/module.html#types.
+Note that in some cases, signficant performance degradation can occur when
+using these types vs. not, in particular when specifying ``cx_Oracle.CLOB``.
+
+On the SQLAlchemy side, the :meth:`.DialectEvents.do_setinputsizes` event can
+be used both for runtime visibliity (e.g. logging) of the setinputsizes step as
+well as to fully control how ``setinputsizes()`` is used on a per-statement
basis.
.. versionadded:: 1.2.9 Added :meth:`.DialectEvents.setinputsizes`
@@ -155,8 +156,8 @@ basis.
Example 1 - logging all setinputsizes calls
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-The following example illustrates how to log the intermediary values from
-a SQLAlchemy perspective before they are converted to the raw ``setinputsizes()``
+The following example illustrates how to log the intermediary values from a
+SQLAlchemy perspective before they are converted to the raw ``setinputsizes()``
parameter dictionary. The keys of the dictionary are :class:`.BindParameter`
objects which have a ``.key`` and a ``.type`` attribute::
@@ -273,24 +274,31 @@ SQLAlchemy type (or a subclass of such).
reworked to take advantage of newer cx_Oracle features as well
as better integration of outputtypehandlers.
-"""
+""" # noqa
from __future__ import absolute_import
-from .base import OracleCompiler, OracleDialect, OracleExecutionContext
-from . import base as oracle
-from ...engine import result as _result
-from sqlalchemy import types as sqltypes, util, exc, processors
-from ...util import compat
-import random
import collections
import decimal
+import random
import re
+from . import base as oracle
+from .base import OracleCompiler
+from .base import OracleDialect
+from .base import OracleExecutionContext
+from ... import exc
+from ... import processors
+from ... import types as sqltypes
+from ... import util
+from ...engine import result as _result
+from ...util import compat
+
class _OracleInteger(sqltypes.Integer):
def get_dbapi_type(self, dbapi):
- # see https://github.com/oracle/python-cx_Oracle/issues/208#issuecomment-409715955
+ # see https://github.com/oracle/python-cx_Oracle/issues/
+ # 208#issuecomment-409715955
return int
def _cx_oracle_var(self, dialect, cursor):
@@ -642,8 +650,8 @@ class OracleExecutionContext_cx_oracle(OracleExecutionContext):
for bind, name in self.compiled.bind_names.items():
if name in self.out_parameters:
- type = bind.type
- impl_type = type.dialect_impl(self.dialect)
+ type_ = bind.type
+ impl_type = type_.dialect_impl(self.dialect)
dbapi_type = impl_type.get_dbapi_type(
self.dialect.dbapi
)
@@ -1073,8 +1081,8 @@ class OracleDialect_cx_oracle(OracleDialect):
"""
- id = random.randint(0, 2 ** 128)
- return (0x1234, "%032x" % id, "%032x" % 9)
+ id_ = random.randint(0, 2 ** 128)
+ return (0x1234, "%032x" % id_, "%032x" % 9)
def do_executemany(self, cursor, statement, parameters, context=None):
if isinstance(parameters, tuple):
diff --git a/lib/sqlalchemy/dialects/oracle/zxjdbc.py b/lib/sqlalchemy/dialects/oracle/zxjdbc.py
index 0a365f8b0..bcd892aa7 100644
--- a/lib/sqlalchemy/dialects/oracle/zxjdbc.py
+++ b/lib/sqlalchemy/dialects/oracle/zxjdbc.py
@@ -15,20 +15,21 @@
.. note:: Jython is not supported by current versions of SQLAlchemy. The
zxjdbc dialect should be considered as experimental.
-"""
+""" # noqa
+import collections
import decimal
import re
-from sqlalchemy import sql, types as sqltypes, util
-from sqlalchemy.connectors.zxJDBC import ZxJDBCConnector
-from sqlalchemy.dialects.oracle.base import (
- OracleCompiler,
- OracleDialect,
- OracleExecutionContext,
-)
-from sqlalchemy.engine import result as _result
-from sqlalchemy.sql import expression
-import collections
+from .base import OracleCompiler
+from .base import OracleDialect
+from .base import OracleExecutionContext
+from ... import sql
+from ... import types as sqltypes
+from ... import util
+from ...connectors.zxJDBC import ZxJDBCConnector
+from ...engine import result as _result
+from ...sql import expression
+
SQLException = zxJDBC = None
@@ -173,8 +174,8 @@ class ReturningParam(object):
Specially handled by OracleReturningDataHandler.
"""
- def __init__(self, type):
- self.type = type
+ def __init__(self, type_):
+ self.type = type_
def __eq__(self, other):
if isinstance(other, ReturningParam):
@@ -218,16 +219,16 @@ class OracleDialect_zxjdbc(ZxJDBCConnector, OracleDialect):
class OracleReturningDataHandler(OracleDataHandler):
"""zxJDBC DataHandler that specially handles ReturningParam."""
- def setJDBCObject(self, statement, index, object, dbtype=None):
- if type(object) is ReturningParam:
- statement.registerReturnParameter(index, object.type)
+ def setJDBCObject(self, statement, index, object_, dbtype=None):
+ if type(object_) is ReturningParam:
+ statement.registerReturnParameter(index, object_.type)
elif dbtype is None:
OracleDataHandler.setJDBCObject(
- self, statement, index, object
+ self, statement, index, object_
)
else:
OracleDataHandler.setJDBCObject(
- self, statement, index, object, dbtype
+ self, statement, index, object_, dbtype
)
self.DataHandler = OracleReturningDataHandler
diff --git a/lib/sqlalchemy/dialects/postgresql/__init__.py b/lib/sqlalchemy/dialects/postgresql/__init__.py
index 9e65484fa..a269770d1 100644
--- a/lib/sqlalchemy/dialects/postgresql/__init__.py
+++ b/lib/sqlalchemy/dialects/postgresql/__init__.py
@@ -5,60 +5,61 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from . import (
- base,
- psycopg2,
- pg8000,
- pypostgresql,
- pygresql,
- zxjdbc,
- psycopg2cffi,
-) # noqa
+from . import base
+from . import pg8000 # noqa
+from . import psycopg2 # noqa
+from . import psycopg2cffi # noqa
+from . import pygresql # noqa
+from . import pypostgresql # noqa
+from . import zxjdbc # noqa
+from .array import All
+from .array import Any
+from .array import ARRAY
+from .array import array
+from .base import BIGINT
+from .base import BIT
+from .base import BOOLEAN
+from .base import BYTEA
+from .base import CHAR
+from .base import CIDR
+from .base import CreateEnumType
+from .base import DATE
+from .base import DOUBLE_PRECISION
+from .base import DropEnumType
+from .base import ENUM
+from .base import FLOAT
+from .base import INET
+from .base import INTEGER
+from .base import INTERVAL
+from .base import MACADDR
+from .base import MONEY
+from .base import NUMERIC
+from .base import OID
+from .base import REAL
+from .base import REGCLASS
+from .base import SMALLINT
+from .base import TEXT
+from .base import TIME
+from .base import TIMESTAMP
+from .base import TSVECTOR
+from .base import UUID
+from .base import VARCHAR
+from .dml import Insert
+from .dml import insert
+from .ext import aggregate_order_by
+from .ext import array_agg
+from .ext import ExcludeConstraint
+from .hstore import HSTORE
+from .hstore import hstore
+from .json import JSON
+from .json import JSONB
+from .ranges import DATERANGE
+from .ranges import INT4RANGE
+from .ranges import INT8RANGE
+from .ranges import NUMRANGE
+from .ranges import TSRANGE
+from .ranges import TSTZRANGE
-from .base import (
- INTEGER,
- BIGINT,
- SMALLINT,
- VARCHAR,
- CHAR,
- TEXT,
- NUMERIC,
- FLOAT,
- REAL,
- INET,
- CIDR,
- UUID,
- BIT,
- MACADDR,
- MONEY,
- OID,
- REGCLASS,
- DOUBLE_PRECISION,
- TIMESTAMP,
- TIME,
- DATE,
- BYTEA,
- BOOLEAN,
- INTERVAL,
- ENUM,
- TSVECTOR,
- DropEnumType,
- CreateEnumType,
-)
-from .hstore import HSTORE, hstore
-from .json import JSON, JSONB
-from .array import array, ARRAY, Any, All
-from .ext import aggregate_order_by, ExcludeConstraint, array_agg
-from .dml import insert, Insert
-
-from .ranges import (
- INT4RANGE,
- INT8RANGE,
- NUMRANGE,
- DATERANGE,
- TSRANGE,
- TSTZRANGE,
-)
base.dialect = dialect = psycopg2.dialect
@@ -98,6 +99,7 @@ __all__ = (
"INT8RANGE",
"NUMRANGE",
"DATERANGE",
+ "TSVECTOR",
"TSRANGE",
"TSTZRANGE",
"JSON",
diff --git a/lib/sqlalchemy/dialects/postgresql/array.py b/lib/sqlalchemy/dialects/postgresql/array.py
index 07167f9d0..af1469880 100644
--- a/lib/sqlalchemy/dialects/postgresql/array.py
+++ b/lib/sqlalchemy/dialects/postgresql/array.py
@@ -5,13 +5,15 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .base import ischema_names, colspecs
-from ...sql import expression, operators
-from ...sql.base import SchemaEventTarget
+from .base import colspecs
+from .base import ischema_names
from ... import types as sqltypes
+from ...sql import expression
+from ...sql import operators
+
try:
- from uuid import UUID as _python_UUID
+ from uuid import UUID as _python_UUID # noqa
except ImportError:
_python_UUID = None
@@ -142,13 +144,14 @@ class ARRAY(sqltypes.ARRAY):
)
The :class:`.postgresql.ARRAY` type provides all operations defined on the
- core :class:`.types.ARRAY` type, including support for "dimensions", indexed
- access, and simple matching such as :meth:`.types.ARRAY.Comparator.any`
- and :meth:`.types.ARRAY.Comparator.all`. :class:`.postgresql.ARRAY` class also
+ core :class:`.types.ARRAY` type, including support for "dimensions",
+ indexed access, and simple matching such as
+ :meth:`.types.ARRAY.Comparator.any` and
+ :meth:`.types.ARRAY.Comparator.all`. :class:`.postgresql.ARRAY` class also
provides PostgreSQL-specific methods for containment operations, including
:meth:`.postgresql.ARRAY.Comparator.contains`
- :meth:`.postgresql.ARRAY.Comparator.contained_by`,
- and :meth:`.postgresql.ARRAY.Comparator.overlap`, e.g.::
+ :meth:`.postgresql.ARRAY.Comparator.contained_by`, and
+ :meth:`.postgresql.ARRAY.Comparator.overlap`, e.g.::
mytable.c.data.contains([1, 2])
diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py
index 11833da57..e77b2880f 100644
--- a/lib/sqlalchemy/dialects/postgresql/base.py
+++ b/lib/sqlalchemy/dialects/postgresql/base.py
@@ -290,13 +290,13 @@ use the :meth:`._UpdateBase.returning` method on a per-statement basis::
INSERT...ON CONFLICT (Upsert)
------------------------------
-Starting with version 9.5, PostgreSQL allows "upserts" (update or insert)
-of rows into a table via the ``ON CONFLICT`` clause of the ``INSERT`` statement.
-A candidate row will only be inserted if that row does not violate
-any unique constraints. In the case of a unique constraint violation,
-a secondary action can occur which can be either "DO UPDATE", indicating
-that the data in the target row should be updated, or "DO NOTHING",
-which indicates to silently skip this row.
+Starting with version 9.5, PostgreSQL allows "upserts" (update or insert) of
+rows into a table via the ``ON CONFLICT`` clause of the ``INSERT`` statement. A
+candidate row will only be inserted if that row does not violate any unique
+constraints. In the case of a unique constraint violation, a secondary action
+can occur which can be either "DO UPDATE", indicating that the data in the
+target row should be updated, or "DO NOTHING", which indicates to silently skip
+this row.
Conflicts are determined using existing unique constraints and indexes. These
constraints may be identified either using their name as stated in DDL,
@@ -331,8 +331,9 @@ Both methods supply the "target" of the conflict using either the
named constraint or by column inference:
* The :paramref:`.Insert.on_conflict_do_update.index_elements` argument
- specifies a sequence containing string column names, :class:`.Column` objects,
- and/or SQL expression elements, which would identify a unique index::
+ specifies a sequence containing string column names, :class:`.Column`
+ objects, and/or SQL expression elements, which would identify a unique
+ index::
do_update_stmt = insert_stmt.on_conflict_do_update(
index_elements=['id'],
@@ -915,34 +916,37 @@ E.g.::
"""
from collections import defaultdict
-import re
import datetime as dt
+import re
-
-from sqlalchemy.sql import elements
-from ... import sql, schema, exc, util
-from ...engine import default, reflection
-from ...sql import compiler, expression
+from ... import exc
+from ... import schema
+from ... import sql
+from ... import util
+from ...engine import default
+from ...engine import reflection
+from ...sql import compiler
+from ...sql import elements
+from ...sql import expression
from ...sql import sqltypes
+from ...types import BIGINT
+from ...types import BOOLEAN
+from ...types import CHAR
+from ...types import DATE
+from ...types import FLOAT
+from ...types import INTEGER
+from ...types import NUMERIC
+from ...types import REAL
+from ...types import SMALLINT
+from ...types import TEXT
+from ...types import VARCHAR
+
try:
- from uuid import UUID as _python_UUID
+ from uuid import UUID as _python_UUID # noqa
except ImportError:
_python_UUID = None
-from sqlalchemy.types import (
- INTEGER,
- BIGINT,
- SMALLINT,
- VARCHAR,
- CHAR,
- TEXT,
- FLOAT,
- NUMERIC,
- DATE,
- BOOLEAN,
- REAL,
-)
AUTOCOMMIT_REGEXP = re.compile(
r"\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER|GRANT|REVOKE|"
@@ -2022,7 +2026,7 @@ class PGDDLCompiler(compiler.DDLCompiler):
class PGTypeCompiler(compiler.GenericTypeCompiler):
- def visit_TSVECTOR(self, type, **kw):
+ def visit_TSVECTOR(self, type_, **kw):
return "TSVECTOR"
def visit_INET(self, type_, **kw):
@@ -3087,9 +3091,21 @@ class PGDialect(default.DefaultDialect):
for conname, condef, conschema in c.fetchall():
m = re.search(FK_REGEX, condef).groups()
- constrained_columns, referred_schema, referred_table, referred_columns, _, match, _, onupdate, _, ondelete, deferrable, _, initially = (
- m
- )
+ (
+ constrained_columns,
+ referred_schema,
+ referred_table,
+ referred_columns,
+ _,
+ match,
+ _,
+ onupdate,
+ _,
+ ondelete,
+ deferrable,
+ _,
+ initially,
+ ) = m
if deferrable is not None:
deferrable = True if deferrable == "DEFERRABLE" else False
diff --git a/lib/sqlalchemy/dialects/postgresql/dml.py b/lib/sqlalchemy/dialects/postgresql/dml.py
index 825f13238..9698e36ba 100644
--- a/lib/sqlalchemy/dialects/postgresql/dml.py
+++ b/lib/sqlalchemy/dialects/postgresql/dml.py
@@ -5,14 +5,15 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from ...sql.elements import ClauseElement, _literal_as_binds
+from . import ext
+from ... import util
+from ...sql import schema
+from ...sql.base import _generative
from ...sql.dml import Insert as StandardInsert
+from ...sql.elements import ClauseElement
from ...sql.expression import alias
-from ...sql import schema
from ...util.langhelpers import public_factory
-from ...sql.base import _generative
-from ... import util
-from . import ext
+
__all__ = ("Insert", "insert")
@@ -51,7 +52,7 @@ class Insert(StandardInsert):
set_=None,
where=None,
):
- """
+ r"""
Specifies a DO UPDATE SET action for ON CONFLICT clause.
Either the ``constraint`` or ``index_elements`` argument is
@@ -70,7 +71,7 @@ class Insert(StandardInsert):
Additional WHERE criterion that can be used to infer a
conditional target index.
- :param set_:
+ :param set\_:
Required argument. A dictionary or other mapping object
with column names as keys and expressions or literals as values,
specifying the ``SET`` actions to take.
diff --git a/lib/sqlalchemy/dialects/postgresql/ext.py b/lib/sqlalchemy/dialects/postgresql/ext.py
index da0c6250c..7f97d6e32 100644
--- a/lib/sqlalchemy/dialects/postgresql/ext.py
+++ b/lib/sqlalchemy/dialects/postgresql/ext.py
@@ -5,11 +5,11 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from ...sql import expression
+from .array import ARRAY
from ...sql import elements
+from ...sql import expression
from ...sql import functions
from ...sql.schema import ColumnCollectionConstraint
-from .array import ARRAY
class aggregate_order_by(expression.ColumnElement):
@@ -83,9 +83,9 @@ class ExcludeConstraint(ColumnCollectionConstraint):
Defines an EXCLUDE constraint as described in the `postgres
documentation`__.
- __ http://www.postgresql.org/docs/9.0/\
-static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
- """
+ __ http://www.postgresql.org/docs/9.0/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE
+
+ """ # noqa
__visit_name__ = "exclude_constraint"
diff --git a/lib/sqlalchemy/dialects/postgresql/hstore.py b/lib/sqlalchemy/dialects/postgresql/hstore.py
index e4bac692a..b1511acd4 100644
--- a/lib/sqlalchemy/dialects/postgresql/hstore.py
+++ b/lib/sqlalchemy/dialects/postgresql/hstore.py
@@ -7,12 +7,13 @@
import re
-from .base import ischema_names
from .array import ARRAY
+from .base import ischema_names
from ... import types as sqltypes
+from ... import util
from ...sql import functions as sqlfunc
from ...sql import operators
-from ... import util
+
__all__ = ("HSTORE", "hstore")
diff --git a/lib/sqlalchemy/dialects/postgresql/json.py b/lib/sqlalchemy/dialects/postgresql/json.py
index f9421de37..1ac040abc 100644
--- a/lib/sqlalchemy/dialects/postgresql/json.py
+++ b/lib/sqlalchemy/dialects/postgresql/json.py
@@ -6,11 +6,12 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
from __future__ import absolute_import
-from .base import ischema_names, colspecs
+from .base import colspecs
+from .base import ischema_names
from ... import types as sqltypes
-from ...sql import operators
-from ...sql import elements
from ... import util
+from ...sql import operators
+
__all__ = ("JSON", "JSONB")
@@ -133,8 +134,7 @@ class JSON(sqltypes.JSON):
* Path index operations returning text (the ``#>>`` operator)::
- data_table.c.data[('key_1', 'key_2', 5, ..., 'key_n')].astext == \
-'some value'
+ data_table.c.data[('key_1', 'key_2', 5, ..., 'key_n')].astext == 'some value'
.. versionchanged:: 1.1 The :meth:`.ColumnElement.cast` operator on
JSON objects now requires that the :attr:`.JSON.Comparator.astext`
@@ -164,7 +164,7 @@ class JSON(sqltypes.JSON):
:class:`.JSONB`
- """
+ """ # noqa
astext_type = sqltypes.Text()
diff --git a/lib/sqlalchemy/dialects/postgresql/pg8000.py b/lib/sqlalchemy/dialects/postgresql/pg8000.py
index fef09e0eb..1eb24668b 100644
--- a/lib/sqlalchemy/dialects/postgresql/pg8000.py
+++ b/lib/sqlalchemy/dialects/postgresql/pg8000.py
@@ -4,13 +4,11 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-
-"""
+r"""
.. dialect:: postgresql+pg8000
:name: pg8000
:dbapi: pg8000
- :connectstring: \
-postgresql+pg8000://user:password@host:port/dbname[?key=value&key=value...]
+ :connectstring: postgresql+pg8000://user:password@host:port/dbname[?key=value&key=value...]
:url: https://pythonhosted.org/pg8000/
@@ -63,27 +61,28 @@ of the :ref:`psycopg2 <psycopg2_isolation_level>` dialect:
:ref:`psycopg2_isolation_level`
-"""
-from ... import util, exc
+""" # noqa
import decimal
+import re
+
+from .base import _DECIMAL_TYPES
+from .base import _FLOAT_TYPES
+from .base import _INT_TYPES
+from .base import PGCompiler
+from .base import PGDialect
+from .base import PGExecutionContext
+from .base import PGIdentifierPreparer
+from .base import UUID
+from .json import JSON
+from ... import exc
from ... import processors
from ... import types as sqltypes
-from .base import (
- PGDialect,
- PGCompiler,
- PGIdentifierPreparer,
- PGExecutionContext,
- _DECIMAL_TYPES,
- _FLOAT_TYPES,
- _INT_TYPES,
- UUID,
-)
-import re
-from sqlalchemy.dialects.postgresql.json import JSON
+from ... import util
from ...sql.elements import quoted_name
+
try:
- from uuid import UUID as _python_UUID
+ from uuid import UUID as _python_UUID # noqa
except ImportError:
_python_UUID = None
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
index 2c27c6919..30203d204 100644
--- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py
@@ -4,7 +4,6 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-
r"""
.. dialect:: postgresql+psycopg2
:name: psycopg2
@@ -77,12 +76,12 @@ in ``/tmp``, or whatever socket directory was specified when PostgreSQL
was built. This value can be overridden by passing a pathname to psycopg2,
using ``host`` as an additional keyword argument::
- create_engine("postgresql+psycopg2://user:password@/dbname?\
-host=/var/lib/postgresql")
+ create_engine("postgresql+psycopg2://user:password@/dbname?host=/var/lib/postgresql")
.. seealso::
- `PQconnectdbParams <http://www.postgresql.org/docs/9.1/static/libpq-connect.html#LIBPQ-PQCONNECTDBPARAMS>`_
+ `PQconnectdbParams \
+ <http://www.postgresql.org/docs/9.1/static/libpq-connect.html#LIBPQ-PQCONNECTDBPARAMS>`_
.. _psycopg2_execution_options:
@@ -93,13 +92,13 @@ The following DBAPI-specific options are respected when used with
:meth:`.Connection.execution_options`, :meth:`.Executable.execution_options`,
:meth:`.Query.execution_options`, in addition to those not specific to DBAPIs:
-* ``isolation_level`` - Set the transaction isolation level for the lifespan of a
- :class:`.Connection` (can only be set on a connection, not a statement
+* ``isolation_level`` - Set the transaction isolation level for the lifespan
+ of a :class:`.Connection` (can only be set on a connection, not a statement
or query). See :ref:`psycopg2_isolation_level`.
-* ``stream_results`` - Enable or disable usage of psycopg2 server side cursors -
- this feature makes use of "named" cursors in combination with special
- result handling methods so that result rows are not fully buffered.
+* ``stream_results`` - Enable or disable usage of psycopg2 server side
+ cursors - this feature makes use of "named" cursors in combination with
+ special result handling methods so that result rows are not fully buffered.
If ``None`` or not set, the ``server_side_cursors`` option of the
:class:`.Engine` is used.
@@ -116,7 +115,8 @@ Psycopg2 Batch Mode (Fast Execution)
------------------------------------
Modern versions of psycopg2 include a feature known as
-`Fast Execution Helpers <http://initd.org/psycopg/docs/extras.html#fast-execution-helpers>`_,
+`Fast Execution Helpers \
+<http://initd.org/psycopg/docs/extras.html#fast-execution-helpers>`_,
which have been shown in benchmarking to improve psycopg2's executemany()
performance with INSERTS by multiple orders of magnitude. SQLAlchemy
allows this extension to be used for all ``executemany()`` style calls
@@ -176,10 +176,9 @@ now supported by libpq directly. This is enabled when ``client_encoding``
is passed directly to ``psycopg2.connect()``, and from SQLAlchemy is passed
using the :paramref:`.create_engine.connect_args` parameter::
- # libpq direct parameter setting;
- # only works for PostgreSQL **9.1 and above**
- engine = create_engine("postgresql://user:pass@host/dbname",
- connect_args={'client_encoding': 'utf8'})
+ engine = create_engine(
+ "postgresql://user:pass@host/dbname",
+ connect_args={'client_encoding': 'utf8'})
# using the query string is equivalent
engine = create_engine("postgresql://user:pass@host/dbname?client_encoding=utf8")
@@ -294,8 +293,8 @@ The psycopg2 dialect supports these constants for isolation level:
NOTICE logging
---------------
-The psycopg2 dialect will log PostgreSQL NOTICE messages via the
-``sqlalchemy.dialects.postgresql`` logger::
+The psycopg2 dialect will log PostgreSQL NOTICE messages
+via the ``sqlalchemy.dialects.postgresql`` logger::
import logging
logging.getLogger('sqlalchemy.dialects.postgresql').setLevel(logging.INFO)
@@ -341,34 +340,34 @@ string format, on both the parameter side and the result side, will take
place within SQLAlchemy's own marshalling logic, and not that of ``psycopg2``
which may be more performant.
-"""
+""" # noqa
from __future__ import absolute_import
-import re
+import decimal
import logging
+import re
-from ... import util, exc
-import decimal
+from .base import _DECIMAL_TYPES
+from .base import _FLOAT_TYPES
+from .base import _INT_TYPES
+from .base import ENUM
+from .base import PGCompiler
+from .base import PGDialect
+from .base import PGExecutionContext
+from .base import PGIdentifierPreparer
+from .base import UUID
+from .hstore import HSTORE
+from .json import JSON
+from .json import JSONB
+from ... import exc
from ... import processors
-from ...engine import result as _result
-from ...sql import expression
from ... import types as sqltypes
-from .base import (
- PGDialect,
- PGCompiler,
- PGIdentifierPreparer,
- PGExecutionContext,
- ENUM,
- _DECIMAL_TYPES,
- _FLOAT_TYPES,
- _INT_TYPES,
- UUID,
-)
-from .hstore import HSTORE
-from .json import JSON, JSONB
+from ... import util
+from ...engine import result as _result
+
try:
- from uuid import UUID as _python_UUID
+ from uuid import UUID as _python_UUID # noqa
except ImportError:
_python_UUID = None
@@ -448,7 +447,6 @@ class _PGJSONB(JSONB):
class _PGUUID(UUID):
def bind_processor(self, dialect):
if not self.as_uuid and dialect.use_native_uuid:
- nonetype = type(None)
def process(value):
if value is not None:
diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py b/lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py
index 7343bc973..c31527a44 100644
--- a/lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py
+++ b/lib/sqlalchemy/dialects/postgresql/psycopg2cffi.py
@@ -4,13 +4,11 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-"""
+r"""
.. dialect:: postgresql+psycopg2cffi
:name: psycopg2cffi
:dbapi: psycopg2cffi
- :connectstring: \
-postgresql+psycopg2cffi://user:password@host:port/dbname\
-[?key=value&key=value...]
+ :connectstring: postgresql+psycopg2cffi://user:password@host:port/dbname[?key=value&key=value...]
:url: http://pypi.python.org/pypi/psycopg2cffi/
``psycopg2cffi`` is an adaptation of ``psycopg2``, using CFFI for the C
@@ -23,7 +21,7 @@ is as per ``psycopg2``.
:mod:`sqlalchemy.dialects.postgresql.psycopg2`
-"""
+""" # noqa
from .psycopg2 import PGDialect_psycopg2
diff --git a/lib/sqlalchemy/dialects/postgresql/pygresql.py b/lib/sqlalchemy/dialects/postgresql/pygresql.py
index c7edb8fc3..13a3118b5 100644
--- a/lib/sqlalchemy/dialects/postgresql/pygresql.py
+++ b/lib/sqlalchemy/dialects/postgresql/pygresql.py
@@ -4,33 +4,33 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-
"""
.. dialect:: postgresql+pygresql
:name: pygresql
:dbapi: pgdb
- :connectstring: postgresql+pygresql://user:password@host:port/dbname\
-[?key=value&key=value...]
+ :connectstring: postgresql+pygresql://user:password@host:port/dbname[?key=value&key=value...]
:url: http://www.pygresql.org/
-"""
+""" # noqa
import decimal
import re
-from ... import exc, processors, util
-from ...types import Numeric, JSON as Json
-from ...sql.elements import Null
-from .base import (
- PGDialect,
- PGCompiler,
- PGIdentifierPreparer,
- _DECIMAL_TYPES,
- _FLOAT_TYPES,
- _INT_TYPES,
- UUID,
-)
+from .base import _DECIMAL_TYPES
+from .base import _FLOAT_TYPES
+from .base import _INT_TYPES
+from .base import PGCompiler
+from .base import PGDialect
+from .base import PGIdentifierPreparer
+from .base import UUID
from .hstore import HSTORE
-from .json import JSON, JSONB
+from .json import JSON
+from .json import JSONB
+from ... import exc
+from ... import processors
+from ... import util
+from ...sql.elements import Null
+from ...types import JSON as Json
+from ...types import Numeric
class _PGNumeric(Numeric):
diff --git a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
index 93bf653a4..398ac290d 100644
--- a/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
+++ b/lib/sqlalchemy/dialects/postgresql/pypostgresql.py
@@ -4,21 +4,21 @@
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-
"""
.. dialect:: postgresql+pypostgresql
:name: py-postgresql
:dbapi: pypostgresql
- :connectstring: postgresql+pypostgresql://user:password@host:port/dbname\
-[?key=value&key=value...]
+ :connectstring: postgresql+pypostgresql://user:password@host:port/dbname[?key=value&key=value...]
:url: http://python.projects.pgfoundry.org/
-"""
-from ... import util
-from ... import types as sqltypes
-from .base import PGDialect, PGExecutionContext
+""" # noqa
+
+from .base import PGDialect
+from .base import PGExecutionContext
from ... import processors
+from ... import types as sqltypes
+from ... import util
class PGNumeric(sqltypes.Numeric):
diff --git a/lib/sqlalchemy/dialects/postgresql/ranges.py b/lib/sqlalchemy/dialects/postgresql/ranges.py
index 62d1275a6..9558f7c48 100644
--- a/lib/sqlalchemy/dialects/postgresql/ranges.py
+++ b/lib/sqlalchemy/dialects/postgresql/ranges.py
@@ -7,6 +7,7 @@
from .base import ischema_names
from ... import types as sqltypes
+
__all__ = ("INT4RANGE", "INT8RANGE", "NUMRANGE")
diff --git a/lib/sqlalchemy/dialects/postgresql/zxjdbc.py b/lib/sqlalchemy/dialects/postgresql/zxjdbc.py
index 4d984443a..ab77e5bc8 100644
--- a/lib/sqlalchemy/dialects/postgresql/zxjdbc.py
+++ b/lib/sqlalchemy/dialects/postgresql/zxjdbc.py
@@ -14,8 +14,9 @@
"""
+from .base import PGDialect
+from .base import PGExecutionContext
from ...connectors.zxJDBC import ZxJDBCConnector
-from .base import PGDialect, PGExecutionContext
class PGExecutionContext_zxjdbc(PGExecutionContext):
diff --git a/lib/sqlalchemy/dialects/sqlite/__init__.py b/lib/sqlalchemy/dialects/sqlite/__init__.py
index 41f017597..fa70717d1 100644
--- a/lib/sqlalchemy/dialects/sqlite/__init__.py
+++ b/lib/sqlalchemy/dialects/sqlite/__init__.py
@@ -5,26 +5,26 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from . import base, pysqlite, pysqlcipher # noqa
+from . import base # noqa
+from . import pysqlcipher # noqa
+from . import pysqlite # noqa
+from .base import BLOB
+from .base import BOOLEAN
+from .base import CHAR
+from .base import DATE
+from .base import DATETIME
+from .base import DECIMAL
+from .base import FLOAT
+from .base import INTEGER
+from .base import JSON
+from .base import NUMERIC
+from .base import REAL
+from .base import SMALLINT
+from .base import TEXT
+from .base import TIME
+from .base import TIMESTAMP
+from .base import VARCHAR
-from sqlalchemy.dialects.sqlite.base import (
- BLOB,
- BOOLEAN,
- CHAR,
- DATE,
- DATETIME,
- DECIMAL,
- FLOAT,
- INTEGER,
- JSON,
- REAL,
- NUMERIC,
- SMALLINT,
- TEXT,
- TIME,
- TIMESTAMP,
- VARCHAR,
-)
# default dialect
base.dialect = dialect = pysqlite.dialect
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py
index cb9389af1..1eea2b6c6 100644
--- a/lib/sqlalchemy/dialects/sqlite/base.py
+++ b/lib/sqlalchemy/dialects/sqlite/base.py
@@ -36,7 +36,8 @@ so that the column continues to have textual affinity.
.. seealso::
- `Type Affinity <http://www.sqlite.org/datatype3.html#affinity>`_ - in the SQLite documentation
+ `Type Affinity <http://www.sqlite.org/datatype3.html#affinity>`_ -
+ in the SQLite documentation
.. _sqlite_autoincrement:
@@ -71,18 +72,16 @@ construct::
Allowing autoincrement behavior SQLAlchemy types other than Integer/INTEGER
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-SQLite's typing model is based on naming conventions. Among
-other things, this means that any type name which contains the
-substring ``"INT"`` will be determined to be of "integer affinity". A
-type named ``"BIGINT"``, ``"SPECIAL_INT"`` or even ``"XYZINTQPR"``, will be considered by
-SQLite to be of "integer" affinity. However, **the SQLite
-autoincrement feature, whether implicitly or explicitly enabled,
-requires that the name of the column's type
-is exactly the string "INTEGER"**. Therefore, if an
-application uses a type like :class:`.BigInteger` for a primary key, on
-SQLite this type will need to be rendered as the name ``"INTEGER"`` when
-emitting the initial ``CREATE TABLE`` statement in order for the autoincrement
-behavior to be available.
+SQLite's typing model is based on naming conventions. Among other things, this
+means that any type name which contains the substring ``"INT"`` will be
+determined to be of "integer affinity". A type named ``"BIGINT"``,
+``"SPECIAL_INT"`` or even ``"XYZINTQPR"``, will be considered by SQLite to be
+of "integer" affinity. However, **the SQLite autoincrement feature, whether
+implicitly or explicitly enabled, requires that the name of the column's type
+is exactly the string "INTEGER"**. Therefore, if an application uses a type
+like :class:`.BigInteger` for a primary key, on SQLite this type will need to
+be rendered as the name ``"INTEGER"`` when emitting the initial ``CREATE
+TABLE`` statement in order for the autoincrement behavior to be available.
One approach to achieve this is to use :class:`.Integer` on SQLite
only using :meth:`.TypeEngine.with_variant`::
@@ -92,8 +91,8 @@ only using :meth:`.TypeEngine.with_variant`::
Column("id", BigInteger().with_variant(Integer, "sqlite"), primary_key=True)
)
-Another is to use a subclass of :class:`.BigInteger` that overrides its DDL name
-to be ``INTEGER`` when compiled against SQLite::
+Another is to use a subclass of :class:`.BigInteger` that overrides its DDL
+name to be ``INTEGER`` when compiled against SQLite::
from sqlalchemy import BigInteger
from sqlalchemy.ext.compiler import compiles
@@ -173,7 +172,8 @@ Transaction Isolation Level
----------------------------
SQLite supports "transaction isolation" in a non-standard way, along two
-axes. One is that of the `PRAGMA read_uncommitted <http://www.sqlite.org/pragma.html#pragma_read_uncommitted>`_
+axes. One is that of the
+`PRAGMA read_uncommitted <http://www.sqlite.org/pragma.html#pragma_read_uncommitted>`_
instruction. This setting can essentially switch SQLite between its
default mode of ``SERIALIZABLE`` isolation, and a "dirty read" isolation
mode normally referred to as ``READ UNCOMMITTED``.
@@ -546,12 +546,12 @@ names are still addressable*::
1
Therefore, the workaround applied by SQLAlchemy only impacts
-:meth:`.ResultProxy.keys` and :meth:`.RowProxy.keys()` in the public API.
-In the very specific case where
-an application is forced to use column names that contain dots, and the
-functionality of :meth:`.ResultProxy.keys` and :meth:`.RowProxy.keys()`
-is required to return these dotted names unmodified, the ``sqlite_raw_colnames``
-execution option may be provided, either on a per-:class:`.Connection` basis::
+:meth:`.ResultProxy.keys` and :meth:`.RowProxy.keys()` in the public API. In
+the very specific case where an application is forced to use column names that
+contain dots, and the functionality of :meth:`.ResultProxy.keys` and
+:meth:`.RowProxy.keys()` is required to return these dotted names unmodified,
+the ``sqlite_raw_colnames`` execution option may be provided, either on a
+per-:class:`.Connection` basis::
result = conn.execution_options(sqlite_raw_colnames=True).execute('''
select x.a, x.b from x where a=1
@@ -567,33 +567,35 @@ or on a per-:class:`.Engine` basis::
When using the per-:class:`.Engine` execution option, note that
**Core and ORM queries that use UNION may not function properly**.
-"""
+""" # noqa
import datetime
import re
+from .json import JSON
+from .json import JSONIndexType
+from .json import JSONPathType
+from ... import exc
from ... import processors
-from ... import sql, exc
-from ... import types as sqltypes, schema as sa_schema
+from ... import schema as sa_schema
+from ... import sql
+from ... import types as sqltypes
from ... import util
-from ...engine import default, reflection
+from ...engine import default
+from ...engine import reflection
from ...sql import compiler
-
-from ...types import (
- BLOB,
- BOOLEAN,
- CHAR,
- DECIMAL,
- FLOAT,
- INTEGER,
- REAL,
- NUMERIC,
- SMALLINT,
- TEXT,
- TIMESTAMP,
- VARCHAR,
-)
-from .json import JSON, JSONIndexType, JSONPathType
+from ...types import BLOB # noqa
+from ...types import BOOLEAN # noqa
+from ...types import CHAR # noqa
+from ...types import DECIMAL # noqa
+from ...types import FLOAT # noqa
+from ...types import INTEGER # noqa
+from ...types import NUMERIC # noqa
+from ...types import REAL # noqa
+from ...types import SMALLINT # noqa
+from ...types import TEXT # noqa
+from ...types import TIMESTAMP # noqa
+from ...types import VARCHAR # noqa
class _DateTimeMixin(object):
@@ -680,7 +682,7 @@ class DATETIME(_DateTimeMixin, sqltypes.DateTime):
is called with positional arguments via
``*map(int, match_obj.groups(0))``.
- """
+ """ # noqa
_storage_format = (
"%(year)04d-%(month)02d-%(day)02d "
@@ -707,13 +709,13 @@ class DATETIME(_DateTimeMixin, sqltypes.DateTime):
def bind_processor(self, dialect):
datetime_datetime = datetime.datetime
datetime_date = datetime.date
- format = self._storage_format
+ format_ = self._storage_format
def process(value):
if value is None:
return None
elif isinstance(value, datetime_datetime):
- return format % {
+ return format_ % {
"year": value.year,
"month": value.month,
"day": value.day,
@@ -723,7 +725,7 @@ class DATETIME(_DateTimeMixin, sqltypes.DateTime):
"microsecond": value.microsecond,
}
elif isinstance(value, datetime_date):
- return format % {
+ return format_ % {
"year": value.year,
"month": value.month,
"day": value.day,
@@ -786,13 +788,13 @@ class DATE(_DateTimeMixin, sqltypes.Date):
def bind_processor(self, dialect):
datetime_date = datetime.date
- format = self._storage_format
+ format_ = self._storage_format
def process(value):
if value is None:
return None
elif isinstance(value, datetime_date):
- return format % {
+ return format_ % {
"year": value.year,
"month": value.month,
"day": value.day,
@@ -864,13 +866,13 @@ class TIME(_DateTimeMixin, sqltypes.Time):
def bind_processor(self, dialect):
datetime_time = datetime.time
- format = self._storage_format
+ format_ = self._storage_format
def process(value):
if value is None:
return None
elif isinstance(value, datetime_time):
- return format % {
+ return format_ % {
"hour": value.hour,
"minute": value.minute,
"second": value.second,
diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlcipher.py b/lib/sqlalchemy/dialects/sqlite/pysqlcipher.py
index fca425127..66abef38f 100644
--- a/lib/sqlalchemy/dialects/sqlite/pysqlcipher.py
+++ b/lib/sqlalchemy/dialects/sqlite/pysqlcipher.py
@@ -25,7 +25,8 @@
Driver
------
-The driver here is the `pysqlcipher <https://pypi.python.org/pypi/pysqlcipher>`_
+The driver here is the
+`pysqlcipher <https://pypi.python.org/pypi/pysqlcipher>`_
driver, which makes use of the SQLCipher engine. This system essentially
introduces new PRAGMA commands to SQLite which allows the setting of a
passphrase and other encryption parameters, allowing the database
@@ -74,11 +75,13 @@ to prevent unencrypted connections from being held open for long periods of
time, at the expense of slower startup time for new connections.
-"""
+""" # noqa
+
from __future__ import absolute_import
+
from .pysqlite import SQLiteDialect_pysqlite
-from ...engine import url as _url
from ... import pool
+from ...engine import url as _url
class SQLiteDialect_pysqlcipher(SQLiteDialect_pysqlite):
diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py
index e78d76ae6..67bfa313f 100644
--- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py
+++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py
@@ -246,7 +246,8 @@ integration. Then, at the point at which SQLAlchemy knows that transaction
scope is to begin, we emit ``"BEGIN"`` ourselves.
When we take control of ``"BEGIN"``, we can also control directly SQLite's
-locking modes, introduced at `BEGIN TRANSACTION <http://sqlite.org/lang_transaction.html>`_,
+locking modes, introduced at
+`BEGIN TRANSACTION <http://sqlite.org/lang_transaction.html>`_,
by adding the desired locking mode to our ``"BEGIN"``::
@event.listens_for(engine, "begin")
@@ -255,22 +256,28 @@ by adding the desired locking mode to our ``"BEGIN"``::
.. seealso::
- `BEGIN TRANSACTION <http://sqlite.org/lang_transaction.html>`_ - on the SQLite site
+ `BEGIN TRANSACTION <http://sqlite.org/lang_transaction.html>`_ -
+ on the SQLite site
- `sqlite3 SELECT does not BEGIN a transaction <http://bugs.python.org/issue9924>`_ - on the Python bug tracker
+ `sqlite3 SELECT does not BEGIN a transaction <http://bugs.python.org/issue9924>`_ -
+ on the Python bug tracker
- `sqlite3 module breaks transactions and potentially corrupts data <http://bugs.python.org/issue10740>`_ - on the Python bug tracker
+ `sqlite3 module breaks transactions and potentially corrupts data <http://bugs.python.org/issue10740>`_ -
+ on the Python bug tracker
-"""
-
-from sqlalchemy.dialects.sqlite.base import SQLiteDialect, DATETIME, DATE
-from sqlalchemy import exc, pool
-from sqlalchemy import types as sqltypes
-from sqlalchemy import util
+""" # noqa
import os
+from .base import DATE
+from .base import DATETIME
+from .base import SQLiteDialect
+from ... import exc
+from ... import pool
+from ... import types as sqltypes
+from ... import util
+
class _SQLite_pysqliteTimeStamp(DATETIME):
def bind_processor(self, dialect):
diff --git a/lib/sqlalchemy/dialects/sybase/__init__.py b/lib/sqlalchemy/dialects/sybase/__init__.py
index 2f55d3bf6..9b247fa70 100644
--- a/lib/sqlalchemy/dialects/sybase/__init__.py
+++ b/lib/sqlalchemy/dialects/sybase/__init__.py
@@ -5,34 +5,34 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from . import base, pysybase, pyodbc # noqa
+from . import base # noqa
+from . import pyodbc # noqa
+from . import pysybase # noqa
+from .base import BIGINT
+from .base import BINARY
+from .base import BIT
+from .base import CHAR
+from .base import DATE
+from .base import DATETIME
+from .base import FLOAT
+from .base import IMAGE
+from .base import INT
+from .base import INTEGER
+from .base import MONEY
+from .base import NCHAR
+from .base import NUMERIC
+from .base import NVARCHAR
+from .base import SMALLINT
+from .base import SMALLMONEY
+from .base import TEXT
+from .base import TIME
+from .base import TINYINT
+from .base import UNICHAR
+from .base import UNITEXT
+from .base import UNIVARCHAR
+from .base import VARBINARY
+from .base import VARCHAR
-from .base import (
- CHAR,
- VARCHAR,
- TIME,
- NCHAR,
- NVARCHAR,
- TEXT,
- DATE,
- DATETIME,
- FLOAT,
- NUMERIC,
- BIGINT,
- INT,
- INTEGER,
- SMALLINT,
- BINARY,
- VARBINARY,
- UNITEXT,
- UNICHAR,
- UNIVARCHAR,
- IMAGE,
- BIT,
- MONEY,
- SMALLMONEY,
- TINYINT,
-)
# default dialect
base.dialect = dialect = pyodbc.dialect
diff --git a/lib/sqlalchemy/dialects/sybase/base.py b/lib/sqlalchemy/dialects/sybase/base.py
index 1214a9279..8fdc011e3 100644
--- a/lib/sqlalchemy/dialects/sybase/base.py
+++ b/lib/sqlalchemy/dialects/sybase/base.py
@@ -21,39 +21,38 @@
caveats not currently handled.
"""
-import operator
+
import re
-from sqlalchemy.sql import compiler, expression, text, bindparam
-from sqlalchemy.engine import default, base, reflection
-from sqlalchemy import types as sqltypes
-from sqlalchemy.sql import operators as sql_operators
+from sqlalchemy import exc
from sqlalchemy import schema as sa_schema
-from sqlalchemy import util, sql, exc
-
-from sqlalchemy.types import (
- CHAR,
- VARCHAR,
- TIME,
- NCHAR,
- NVARCHAR,
- TEXT,
- DATE,
- DATETIME,
- FLOAT,
- NUMERIC,
- BIGINT,
- INT,
- INTEGER,
- SMALLINT,
- BINARY,
- VARBINARY,
- DECIMAL,
- TIMESTAMP,
- Unicode,
- UnicodeText,
- REAL,
-)
+from sqlalchemy import types as sqltypes
+from sqlalchemy import util
+from sqlalchemy.engine import default
+from sqlalchemy.engine import reflection
+from sqlalchemy.sql import compiler
+from sqlalchemy.sql import text
+from sqlalchemy.types import BIGINT
+from sqlalchemy.types import BINARY
+from sqlalchemy.types import CHAR
+from sqlalchemy.types import DATE
+from sqlalchemy.types import DATETIME
+from sqlalchemy.types import DECIMAL
+from sqlalchemy.types import FLOAT
+from sqlalchemy.types import INT # noqa
+from sqlalchemy.types import INTEGER
+from sqlalchemy.types import NCHAR
+from sqlalchemy.types import NUMERIC
+from sqlalchemy.types import NVARCHAR
+from sqlalchemy.types import REAL
+from sqlalchemy.types import SMALLINT
+from sqlalchemy.types import TEXT
+from sqlalchemy.types import TIME
+from sqlalchemy.types import TIMESTAMP
+from sqlalchemy.types import Unicode
+from sqlalchemy.types import VARBINARY
+from sqlalchemy.types import VARCHAR
+
RESERVED_WORDS = set(
[
@@ -696,9 +695,9 @@ class SybaseDialect(default.DefaultDialect):
)
if util.py2k:
- if isinstance(schema, unicode):
+ if isinstance(schema, unicode): # noqa
schema = schema.encode("ascii")
- if isinstance(table_name, unicode):
+ if isinstance(table_name, unicode): # noqa
table_name = table_name.encode("ascii")
result = connection.execute(
TABLEID_SQL, schema_name=schema, table_name=table_name
@@ -740,7 +739,7 @@ class SybaseDialect(default.DefaultDialect):
type_,
nullable,
autoincrement,
- default,
+ default_,
precision,
scale,
length,
@@ -750,7 +749,7 @@ class SybaseDialect(default.DefaultDialect):
type_,
bool(nullable),
bool(autoincrement),
- default,
+ default_,
precision,
scale,
length,
@@ -1037,7 +1036,7 @@ class SybaseDialect(default.DefaultDialect):
)
if util.py2k:
- if isinstance(schema, unicode):
+ if isinstance(schema, unicode): # noqa
schema = schema.encode("ascii")
tables = connection.execute(TABLE_SQL, schema_name=schema)
@@ -1059,7 +1058,7 @@ class SybaseDialect(default.DefaultDialect):
)
if util.py2k:
- if isinstance(view_name, unicode):
+ if isinstance(view_name, unicode): # noqa
view_name = view_name.encode("ascii")
view = connection.execute(VIEW_DEF_SQL, view_name=view_name)
@@ -1081,7 +1080,7 @@ class SybaseDialect(default.DefaultDialect):
)
if util.py2k:
- if isinstance(schema, unicode):
+ if isinstance(schema, unicode): # noqa
schema = schema.encode("ascii")
views = connection.execute(VIEW_SQL, schema_name=schema)
diff --git a/lib/sqlalchemy/dialects/sybase/mxodbc.py b/lib/sqlalchemy/dialects/sybase/mxodbc.py
index eeceb359b..482db9745 100644
--- a/lib/sqlalchemy/dialects/sybase/mxodbc.py
+++ b/lib/sqlalchemy/dialects/sybase/mxodbc.py
@@ -18,9 +18,9 @@
"""
+from sqlalchemy.connectors.mxodbc import MxODBCConnector
from sqlalchemy.dialects.sybase.base import SybaseDialect
from sqlalchemy.dialects.sybase.base import SybaseExecutionContext
-from sqlalchemy.connectors.mxodbc import MxODBCConnector
class SybaseExecutionContext_mxodbc(SybaseExecutionContext):
diff --git a/lib/sqlalchemy/dialects/sybase/pyodbc.py b/lib/sqlalchemy/dialects/sybase/pyodbc.py
index a4759428c..ba299befd 100644
--- a/lib/sqlalchemy/dialects/sybase/pyodbc.py
+++ b/lib/sqlalchemy/dialects/sybase/pyodbc.py
@@ -9,8 +9,7 @@
.. dialect:: sybase+pyodbc
:name: PyODBC
:dbapi: pyodbc
- :connectstring: sybase+pyodbc://<username>:<password>@<dsnname>\
-[/<database>]
+ :connectstring: sybase+pyodbc://<username>:<password>@<dsnname>[/<database>]
:url: http://pypi.python.org/pypi/pyodbc/
@@ -32,16 +31,16 @@ Currently *not* supported are::
UNITEXT
UNIVARCHAR
-"""
+""" # noqa
-from sqlalchemy.dialects.sybase.base import (
- SybaseDialect,
- SybaseExecutionContext,
-)
-from sqlalchemy.connectors.pyodbc import PyODBCConnector
-from sqlalchemy import types as sqltypes, processors
import decimal
+from sqlalchemy import processors
+from sqlalchemy import types as sqltypes
+from sqlalchemy.connectors.pyodbc import PyODBCConnector
+from sqlalchemy.dialects.sybase.base import SybaseDialect
+from sqlalchemy.dialects.sybase.base import SybaseExecutionContext
+
class _SybNumeric_pyodbc(sqltypes.Numeric):
"""Turns Decimals with adjusted() < -6 into floats.
diff --git a/lib/sqlalchemy/dialects/sybase/pysybase.py b/lib/sqlalchemy/dialects/sybase/pysybase.py
index 09d2cf380..9fedc9f26 100644
--- a/lib/sqlalchemy/dialects/sybase/pysybase.py
+++ b/lib/sqlalchemy/dialects/sybase/pysybase.py
@@ -9,8 +9,7 @@
.. dialect:: sybase+pysybase
:name: Python-Sybase
:dbapi: Sybase
- :connectstring: sybase+pysybase://<username>:<password>@<dsn>/\
-[database name]
+ :connectstring: sybase+pysybase://<username>:<password>@<dsn>/[database name]
:url: http://python-sybase.sourceforge.net/
Unicode Support
@@ -19,14 +18,13 @@ Unicode Support
The python-sybase driver does not appear to support non-ASCII strings of any
kind at this time.
-"""
+""" # noqa
-from sqlalchemy import types as sqltypes, processors
-from sqlalchemy.dialects.sybase.base import (
- SybaseDialect,
- SybaseExecutionContext,
- SybaseSQLCompiler,
-)
+from sqlalchemy import processors
+from sqlalchemy import types as sqltypes
+from sqlalchemy.dialects.sybase.base import SybaseDialect
+from sqlalchemy.dialects.sybase.base import SybaseExecutionContext
+from sqlalchemy.dialects.sybase.base import SybaseSQLCompiler
class _SybNumeric(sqltypes.Numeric):
diff --git a/lib/sqlalchemy/engine/__init__.py b/lib/sqlalchemy/engine/__init__.py
index 590359c38..fadc10ad7 100644
--- a/lib/sqlalchemy/engine/__init__.py
+++ b/lib/sqlalchemy/engine/__init__.py
@@ -51,43 +51,33 @@ url.py
within a URL.
"""
-from .interfaces import (
- Connectable,
- CreateEnginePlugin,
- Dialect,
- ExecutionContext,
- ExceptionContext,
- # backwards compat
- Compiled,
- TypeCompiler,
-)
-
-from .base import (
- Connection,
- Engine,
- NestedTransaction,
- RootTransaction,
- Transaction,
- TwoPhaseTransaction,
-)
-
-from .result import (
- BaseRowProxy,
- BufferedColumnResultProxy,
- BufferedColumnRow,
- BufferedRowResultProxy,
- FullyBufferedResultProxy,
- ResultProxy,
- RowProxy,
-)
-
-from .util import connection_memoize
-
-
-from . import util, strategies
+from . import strategies
+from . import util # noqa
+from .base import Connection # noqa
+from .base import Engine # noqa
+from .base import NestedTransaction # noqa
+from .base import RootTransaction # noqa
+from .base import Transaction # noqa
+from .base import TwoPhaseTransaction # noqa
+from .interfaces import Compiled # noqa
+from .interfaces import Connectable # noqa
+from .interfaces import CreateEnginePlugin # noqa
+from .interfaces import Dialect # noqa
+from .interfaces import ExceptionContext # noqa
+from .interfaces import ExecutionContext # noqa
+from .interfaces import TypeCompiler # noqa
+from .result import BaseRowProxy # noqa
+from .result import BufferedColumnResultProxy # noqa
+from .result import BufferedColumnRow # noqa
+from .result import BufferedRowResultProxy # noqa
+from .result import FullyBufferedResultProxy # noqa
+from .result import ResultProxy # noqa
+from .result import RowProxy # noqa
+from .util import connection_memoize # noqa
+from ..sql import ddl # noqa
+
# backwards compat
-from ..sql import ddl
default_strategy = "plain"
@@ -298,8 +288,8 @@ def create_engine(*args, **kwargs):
Behavior here varies per backend, and
individual dialects should be consulted directly.
- Note that the isolation level can also be set on a per-:class:`.Connection`
- basis as well, using the
+ Note that the isolation level can also be set on a
+ per-:class:`.Connection` basis as well, using the
:paramref:`.Connection.execution_options.isolation_level`
feature.
@@ -455,7 +445,7 @@ def create_engine(*args, **kwargs):
``(sql, *multiparams, **params)``, to which the ``mock`` strategy will
dispatch all statement execution. Used only by ``strategy='mock'``.
- """
+ """ # noqa
strategy = kwargs.pop("strategy", default_strategy)
strategy = strategies.strategies[strategy]
diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py
index 75d03b744..c0979ecac 100644
--- a/lib/sqlalchemy/engine/base.py
+++ b/lib/sqlalchemy/engine/base.py
@@ -6,18 +6,23 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
from __future__ import with_statement
-"""Defines :class:`.Connection` and :class:`.Engine`.
+import contextlib
+import sys
-"""
+from .interfaces import Connectable
+from .interfaces import ExceptionContext
+from .util import _distill_params
+from .. import exc
+from .. import interfaces
+from .. import log
+from .. import util
+from ..sql import schema
+from ..sql import util as sql_util
-import sys
-from .. import exc, util, log, interfaces
-from ..sql import util as sql_util
-from ..sql import schema
-from .interfaces import Connectable, ExceptionContext
-from .util import _distill_params
-import contextlib
+"""Defines :class:`.Connection` and :class:`.Engine`.
+
+"""
class Connection(Connectable):
@@ -172,7 +177,7 @@ class Connection(Connectable):
def __enter__(self):
return self
- def __exit__(self, type, value, traceback):
+ def __exit__(self, type_, value, traceback):
self.close()
def execution_options(self, **opt):
@@ -321,7 +326,7 @@ class Connection(Connectable):
:ref:`schema_translating`
- """
+ """ # noqa
c = self._clone()
c._execution_options = c._execution_options.union(opt)
if self._has_events or self.engine._has_events:
@@ -892,15 +897,15 @@ class Connection(Connectable):
self.__can_reconnect = False
self.__transaction = None
- def scalar(self, object, *multiparams, **params):
+ def scalar(self, object_, *multiparams, **params):
"""Executes and returns the first column of the first row.
The underlying result/cursor is closed after execution.
"""
- return self.execute(object, *multiparams, **params).scalar()
+ return self.execute(object_, *multiparams, **params).scalar()
- def execute(self, object, *multiparams, **params):
+ def execute(self, object_, *multiparams, **params):
r"""Executes a SQL statement construct and returns a
:class:`.ResultProxy`.
@@ -959,12 +964,12 @@ class Connection(Connectable):
DBAPI-agnostic way, use the :func:`~.expression.text` construct.
"""
- if isinstance(object, util.string_types[0]):
- return self._execute_text(object, multiparams, params)
+ if isinstance(object_, util.string_types[0]):
+ return self._execute_text(object_, multiparams, params)
try:
- meth = object._execute_on_connection
+ meth = object_._execute_on_connection
except AttributeError:
- raise exc.ObjectNotExecutableError(object)
+ raise exc.ObjectNotExecutableError(object_)
else:
return meth(self, multiparams, params)
@@ -1698,8 +1703,8 @@ class Transaction(object):
def __enter__(self):
return self
- def __exit__(self, type, value, traceback):
- if type is None and self.is_active:
+ def __exit__(self, type_, value, traceback):
+ if type_ is None and self.is_active:
try:
self.commit()
except:
@@ -2005,8 +2010,8 @@ class Engine(Connectable, log.Identified):
def __enter__(self):
return self.conn
- def __exit__(self, type, value, traceback):
- if type is not None:
+ def __exit__(self, type_, value, traceback):
+ if type_ is not None:
self.transaction.rollback()
else:
self.transaction.commit()
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py
index d7c2518fe..cceae74e8 100644
--- a/lib/sqlalchemy/engine/default.py
+++ b/lib/sqlalchemy/engine/default.py
@@ -13,15 +13,24 @@ as the base class for their own corresponding classes.
"""
-import re
-import random
-from . import reflection, interfaces, result
-from ..sql import compiler, expression, schema
-from .. import types as sqltypes
-from .. import exc, util, pool, processors
import codecs
+import random
+import re
import weakref
+
+from . import interfaces
+from . import reflection
+from . import result
from .. import event
+from .. import exc
+from .. import pool
+from .. import processors
+from .. import types as sqltypes
+from .. import util
+from ..sql import compiler
+from ..sql import expression
+from ..sql import schema
+
AUTOCOMMIT_REGEXP = re.compile(
r"\s*(?:UPDATE|INSERT|CREATE|DELETE|DROP|ALTER)", re.I | re.UNICODE
@@ -239,13 +248,13 @@ class DefaultDialect(interfaces.Dialect):
self.label_length = label_length
if self.description_encoding == "use_encoding":
- self._description_decoder = processors.to_unicode_processor_factory(
- encoding
- )
+ self._description_decoder = (
+ processors.to_unicode_processor_factory
+ )(encoding)
elif self.description_encoding is not None:
- self._description_decoder = processors.to_unicode_processor_factory(
- self.description_encoding
- )
+ self._description_decoder = (
+ processors.to_unicode_processor_factory
+ )(self.description_encoding)
self._encoder = codecs.getencoder(self.encoding)
self._decoder = processors.to_unicode_processor_factory(self.encoding)
diff --git a/lib/sqlalchemy/engine/interfaces.py b/lib/sqlalchemy/engine/interfaces.py
index e10e6e884..f738b5caf 100644
--- a/lib/sqlalchemy/engine/interfaces.py
+++ b/lib/sqlalchemy/engine/interfaces.py
@@ -8,9 +8,8 @@
"""Define core interfaces used by the engine system."""
from .. import util
-
-# backwards compat
-from ..sql.compiler import Compiled, TypeCompiler
+from ..sql.compiler import Compiled # noqa
+from ..sql.compiler import TypeCompiler # noqa
class Dialect(object):
@@ -1157,11 +1156,11 @@ class Connectable(object):
raise NotImplementedError()
- def execute(self, object, *multiparams, **params):
+ def execute(self, object_, *multiparams, **params):
"""Executes the given construct and returns a :class:`.ResultProxy`."""
raise NotImplementedError()
- def scalar(self, object, *multiparams, **params):
+ def scalar(self, object_, *multiparams, **params):
"""Executes and returns the first column of the first row.
The underlying cursor is closed after execution.
diff --git a/lib/sqlalchemy/engine/reflection.py b/lib/sqlalchemy/engine/reflection.py
index 9b5fa2459..c822ff820 100644
--- a/lib/sqlalchemy/engine/reflection.py
+++ b/lib/sqlalchemy/engine/reflection.py
@@ -25,14 +25,15 @@ methods such as get_table_names, get_columns, etc.
'name' attribute..
"""
-from .. import exc, sql
-from ..sql import schema as sa_schema
+from .base import Connectable
+from .. import exc
+from .. import inspection
+from .. import sql
from .. import util
+from ..sql import schema as sa_schema
from ..sql.type_api import TypeEngine
from ..util import deprecated
from ..util import topological
-from .. import inspection
-from .base import Connectable
@util.decorator
diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index 5ad0d2909..d672ffefe 100644
--- a/lib/sqlalchemy/engine/result.py
+++ b/lib/sqlalchemy/engine/result.py
@@ -9,11 +9,16 @@
and :class:`.RowProxy."""
-from .. import exc, util
-from ..sql import expression, sqltypes, util as sql_util
import collections
import operator
+from .. import exc
+from .. import util
+from ..sql import expression
+from ..sql import sqltypes
+from ..sql import util as sql_util
+
+
# This reconstructor is necessary so that pickles with the C extension or
# without use the same Binary format.
try:
@@ -443,7 +448,14 @@ class ResultMetaData(object):
obj,
untranslated,
)
- for idx, colname, mapped_type, coltype, obj, untranslated in raw_iterator
+ for (
+ idx,
+ colname,
+ mapped_type,
+ coltype,
+ obj,
+ untranslated,
+ ) in raw_iterator
]
def _colnames_from_description(self, context, cursor_description):
@@ -575,10 +587,10 @@ class ResultMetaData(object):
return d
def _key_fallback(self, key, raiseerr=True):
- map = self._keymap
+ map_ = self._keymap
result = None
if isinstance(key, util.string_types):
- result = map.get(key if self.case_sensitive else key.lower())
+ result = map_.get(key if self.case_sensitive else key.lower())
# fallback for targeting a ColumnElement to a textual expression
# this is a rare use case which only occurs when matching text()
# or colummn('name') constructs to ColumnElements, or after a
@@ -587,18 +599,18 @@ class ResultMetaData(object):
if (
key._label
and (key._label if self.case_sensitive else key._label.lower())
- in map
+ in map_
):
- result = map[
+ result = map_[
key._label if self.case_sensitive else key._label.lower()
]
elif (
hasattr(key, "name")
and (key.name if self.case_sensitive else key.name.lower())
- in map
+ in map_
):
# match is only on name.
- result = map[
+ result = map_[
key.name if self.case_sensitive else key.name.lower()
]
# search extra hard to make sure this
@@ -620,7 +632,7 @@ class ResultMetaData(object):
else:
return None
else:
- map[key] = result
+ map_[key] = result
return result
def _has_key(self, key):
diff --git a/lib/sqlalchemy/engine/strategies.py b/lib/sqlalchemy/engine/strategies.py
index 4aecb9537..e16460d86 100644
--- a/lib/sqlalchemy/engine/strategies.py
+++ b/lib/sqlalchemy/engine/strategies.py
@@ -17,10 +17,14 @@ New strategies can be added via new ``EngineStrategy`` classes.
from operator import attrgetter
-from sqlalchemy.engine import base, threadlocal, url
-from sqlalchemy import util, event
-from sqlalchemy import pool as poollib
-from sqlalchemy.sql import schema
+from . import base
+from . import threadlocal
+from . import url
+from .. import event
+from .. import pool as poollib
+from .. import util
+from ..sql import schema
+
strategies = {}
@@ -299,7 +303,7 @@ class MockEngineStrategy(EngineStrategy):
element
)
- def execute(self, object, *multiparams, **params):
+ def execute(self, object_, *multiparams, **params):
raise NotImplementedError()
diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py
index 5b2bdabc0..b34d510f7 100644
--- a/lib/sqlalchemy/engine/threadlocal.py
+++ b/lib/sqlalchemy/engine/threadlocal.py
@@ -13,10 +13,11 @@ This module is semi-private and is invoked automatically when the threadlocal
engine strategy is used.
"""
-from .. import util
-from . import base
import weakref
+from . import base
+from .. import util
+
class TLConnection(base.Connection):
def __init__(self, *arg, **kw):
@@ -92,8 +93,8 @@ class TLEngine(base.Engine):
def __enter__(self):
return self
- def __exit__(self, type, value, traceback):
- if type is None:
+ def __exit__(self, type_, value, traceback):
+ if type_ is None:
self.commit()
else:
self.rollback()
diff --git a/lib/sqlalchemy/engine/url.py b/lib/sqlalchemy/engine/url.py
index e92e57b8e..f7019d74e 100644
--- a/lib/sqlalchemy/engine/url.py
+++ b/lib/sqlalchemy/engine/url.py
@@ -15,9 +15,12 @@ be used directly and is also accepted directly by ``create_engine()``.
"""
import re
-from .. import exc, util
-from . import Dialect
-from ..dialects import registry, plugins
+
+from .interfaces import Dialect
+from .. import exc
+from .. import util
+from ..dialects import plugins
+from ..dialects import registry
class URL(object):
diff --git a/lib/sqlalchemy/engine/util.py b/lib/sqlalchemy/engine/util.py
index 76bb8f4b5..bf8ec13b9 100644
--- a/lib/sqlalchemy/engine/util.py
+++ b/lib/sqlalchemy/engine/util.py
@@ -28,8 +28,8 @@ def connection_memoize(key):
def py_fallback():
- def _distill_params(multiparams, params):
- """Given arguments from the calling form *multiparams, **params,
+ def _distill_params(multiparams, params): # noqa
+ r"""Given arguments from the calling form \*multiparams, \**params,
return a list of bind parameter structures, usually a list of
dictionaries.
@@ -75,6 +75,6 @@ def py_fallback():
try:
- from sqlalchemy.cutils import _distill_params
+ from sqlalchemy.cutils import _distill_params # noqa
except ImportError:
globals().update(py_fallback())
diff --git a/lib/sqlalchemy/event/__init__.py b/lib/sqlalchemy/event/__init__.py
index a7e27e9b6..d38a5e948 100644
--- a/lib/sqlalchemy/event/__init__.py
+++ b/lib/sqlalchemy/event/__init__.py
@@ -5,7 +5,13 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .api import CANCEL, NO_RETVAL, listen, listens_for, remove, contains
-from .base import Events, dispatcher
-from .attr import RefCollection
-from .legacy import _legacy_signature
+from .api import CANCEL # noqa
+from .api import contains # noqa
+from .api import listen # noqa
+from .api import listens_for # noqa
+from .api import NO_RETVAL # noqa
+from .api import remove # noqa
+from .attr import RefCollection # noqa
+from .base import dispatcher # noqa
+from .base import Events # noqa
+from .legacy import _legacy_signature # noqa
diff --git a/lib/sqlalchemy/event/api.py b/lib/sqlalchemy/event/api.py
index f9e04503c..4064b3e21 100644
--- a/lib/sqlalchemy/event/api.py
+++ b/lib/sqlalchemy/event/api.py
@@ -10,9 +10,11 @@
"""
from __future__ import absolute_import
-from .. import util, exc
from .base import _registrars
from .registry import _EventKey
+from .. import exc
+from .. import util
+
CANCEL = util.symbol("CANCEL")
NO_RETVAL = util.symbol("NO_RETVAL")
diff --git a/lib/sqlalchemy/event/attr.py b/lib/sqlalchemy/event/attr.py
index 31a9f28ca..451e0621a 100644
--- a/lib/sqlalchemy/event/attr.py
+++ b/lib/sqlalchemy/event/attr.py
@@ -29,15 +29,18 @@ as well as support for subclass propagation (e.g. events assigned to
"""
-from __future__ import absolute_import, with_statement
+from __future__ import absolute_import
+from __future__ import with_statement
+
+import collections
+from itertools import chain
+import weakref
+
+from . import legacy
+from . import registry
from .. import exc
from .. import util
from ..util import threading
-from . import registry
-from . import legacy
-from itertools import chain
-import weakref
-import collections
class RefCollection(util.MemoizedSlots):
diff --git a/lib/sqlalchemy/event/base.py b/lib/sqlalchemy/event/base.py
index c750be70a..6e3027214 100644
--- a/lib/sqlalchemy/event/base.py
+++ b/lib/sqlalchemy/event/base.py
@@ -19,8 +19,11 @@ from __future__ import absolute_import
import weakref
+from .attr import _ClsLevelDispatch
+from .attr import _EmptyListener
+from .attr import _JoinedListener
from .. import util
-from .attr import _ClsLevelDispatch, _EmptyListener, _JoinedListener
+
_registrars = util.defaultdict(list)
diff --git a/lib/sqlalchemy/event/registry.py b/lib/sqlalchemy/event/registry.py
index c862ae403..86d323982 100644
--- a/lib/sqlalchemy/event/registry.py
+++ b/lib/sqlalchemy/event/registry.py
@@ -17,10 +17,12 @@ an equivalent :class:`._EventKey`.
from __future__ import absolute_import
-import weakref
import collections
import types
-from .. import exc, util
+import weakref
+
+from .. import exc
+from .. import util
_key_to_collection = collections.defaultdict(dict)
@@ -236,11 +238,7 @@ class _EventKey(object):
self, propagate=False, insert=False, named=False, retval=None
):
- target, identifier, fn = (
- self.dispatch_target,
- self.identifier,
- self._listen_fn,
- )
+ target, identifier = self.dispatch_target, self.identifier
dispatch_collection = getattr(target.dispatch, identifier)
diff --git a/lib/sqlalchemy/events.py b/lib/sqlalchemy/events.py
index fa62b7705..01e7b454b 100644
--- a/lib/sqlalchemy/events.py
+++ b/lib/sqlalchemy/events.py
@@ -7,9 +7,12 @@
"""Core event interfaces."""
-from . import event, exc
+from . import event
+from . import exc
+from .engine import Connectable
+from .engine import Dialect
+from .engine import Engine
from .pool import Pool
-from .engine import Connectable, Engine, Dialect
from .sql.base import SchemaEventTarget
@@ -912,11 +915,12 @@ class ConnectionEvents(event.Events):
:meth:`.ConnectionEvents.handle_error` hook.
.. versionchanged:: 1.1 The :meth:`.handle_error` event will now
- receive all exceptions that inherit from ``BaseException``, including
- ``SystemExit`` and ``KeyboardInterrupt``. The setting for
- :attr:`.ExceptionContext.is_disconnect` is ``True`` in this case
- and the default for :attr:`.ExceptionContext.invalidate_pool_on_disconnect`
- is ``False``.
+ receive all exceptions that inherit from ``BaseException``,
+ including ``SystemExit`` and ``KeyboardInterrupt``. The setting for
+ :attr:`.ExceptionContext.is_disconnect` is ``True`` in this case and
+ the default for
+ :attr:`.ExceptionContext.invalidate_pool_on_disconnect` is
+ ``False``.
.. versionchanged:: 1.0.0 The :meth:`.handle_error` event is now
invoked when an :class:`.Engine` fails during the initial
@@ -1191,11 +1195,7 @@ class DialectEvents(event.Events):
@classmethod
def _listen(cls, event_key, retval=False):
- target, identifier, fn = (
- event_key.dispatch_target,
- event_key.identifier,
- event_key.fn,
- )
+ target = event_key.dispatch_target
target._has_events = True
event_key.base_listen()
diff --git a/lib/sqlalchemy/exc.py b/lib/sqlalchemy/exc.py
index 832c5ee52..e47df85af 100644
--- a/lib/sqlalchemy/exc.py
+++ b/lib/sqlalchemy/exc.py
@@ -179,7 +179,7 @@ class InvalidatePoolError(DisconnectionError):
invalidate_pool = True
-class TimeoutError(SQLAlchemyError):
+class TimeoutError(SQLAlchemyError): # noqa
"""Raised when a connection pool times out on getting a connection."""
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:
diff --git a/lib/sqlalchemy/inspection.py b/lib/sqlalchemy/inspection.py
index 7c2ff97c5..6b6bcd688 100644
--- a/lib/sqlalchemy/inspection.py
+++ b/lib/sqlalchemy/inspection.py
@@ -31,7 +31,9 @@ in a forwards-compatible way.
"""
-from . import util, exc
+from . import exc
+from . import util
+
_registrars = util.defaultdict(list)
diff --git a/lib/sqlalchemy/interfaces.py b/lib/sqlalchemy/interfaces.py
index f352f7f26..bde854d24 100644
--- a/lib/sqlalchemy/interfaces.py
+++ b/lib/sqlalchemy/interfaces.py
@@ -13,7 +13,8 @@ event system.
"""
-from . import event, util
+from . import event
+from . import util
class PoolListener(object):
diff --git a/lib/sqlalchemy/log.py b/lib/sqlalchemy/log.py
index 6b0b2e90e..45073ad92 100644
--- a/lib/sqlalchemy/log.py
+++ b/lib/sqlalchemy/log.py
@@ -21,6 +21,7 @@ instance only.
import logging
import sys
+
# set initial level to WARN. This so that
# log statements don't occur in the absence of explicit
# logging being enabled for 'sqlalchemy'.
@@ -73,8 +74,8 @@ class InstanceLogger(object):
'debug' -> logging.DEBUG
True -> logging.INFO
- False -> Effective level of underlying logger
- (logging.WARNING by default)
+ False -> Effective level of underlying logger (
+ logging.WARNING by default)
None -> same as False
"""
diff --git a/lib/sqlalchemy/orm/__init__.py b/lib/sqlalchemy/orm/__init__.py
index 8e7b4cee6..d9f50e153 100644
--- a/lib/sqlalchemy/orm/__init__.py
+++ b/lib/sqlalchemy/orm/__init__.py
@@ -13,53 +13,50 @@ documentation for an overview of how this module is used.
"""
-from . import exc
-from .mapper import (
- Mapper,
- _mapper_registry,
- class_mapper,
- configure_mappers,
- reconstructor,
- validates,
-)
-from .interfaces import EXT_CONTINUE, EXT_STOP, EXT_SKIP, PropComparator
-from .deprecated_interfaces import (
- MapperExtension,
- SessionExtension,
- AttributeExtension,
-)
-from .util import (
- aliased,
- join,
- object_mapper,
- outerjoin,
- polymorphic_union,
- was_deleted,
- with_parent,
- with_polymorphic,
-)
-from .properties import ColumnProperty
-from .relationships import RelationshipProperty
-from .descriptor_props import (
- ComparableProperty,
- CompositeProperty,
- SynonymProperty,
-)
-from .relationships import foreign, remote
-from .session import (
- Session,
- object_session,
- sessionmaker,
- make_transient,
- make_transient_to_detached,
-)
-from .scoping import scoped_session
-from . import mapper as mapperlib
-from .query import AliasOption, Query, Bundle
-from ..util.langhelpers import public_factory
-from .. import util as _sa_util
-from . import strategies as _strategies
+from . import exc # noqa
+from . import mapper as mapperlib # noqa
+from . import strategy_options
+from .deprecated_interfaces import AttributeExtension # noqa
+from .deprecated_interfaces import MapperExtension # noqa
+from .deprecated_interfaces import SessionExtension # noqa
+from .descriptor_props import ComparableProperty # noqa
+from .descriptor_props import CompositeProperty # noqa
+from .descriptor_props import SynonymProperty # noqa
+from .interfaces import EXT_CONTINUE # noqa
+from .interfaces import EXT_SKIP # noqa
+from .interfaces import EXT_STOP # noqa
+from .interfaces import PropComparator # noqa
+from .mapper import _mapper_registry
+from .mapper import class_mapper # noqa
+from .mapper import configure_mappers # noqa
+from .mapper import Mapper # noqa
+from .mapper import reconstructor # noqa
+from .mapper import validates # noqa
+from .properties import ColumnProperty # noqa
+from .query import AliasOption # noqa
+from .query import Bundle # noqa
+from .query import Query # noqa
+from .relationships import foreign # noqa
+from .relationships import RelationshipProperty # noqa
+from .relationships import remote # noqa
+from .scoping import scoped_session # noqa
+from .session import make_transient # noqa
+from .session import make_transient_to_detached # noqa
+from .session import object_session # noqa
+from .session import Session # noqa
+from .session import sessionmaker # noqa
+from .strategy_options import Load # noqa
+from .util import aliased # noqa
+from .util import join # noqa
+from .util import object_mapper # noqa
+from .util import outerjoin # noqa
+from .util import polymorphic_union # noqa
+from .util import was_deleted # noqa
+from .util import with_parent # noqa
+from .util import with_polymorphic # noqa
from .. import sql as _sql
+from .. import util as _sa_util
+from ..util.langhelpers import public_factory
def create_session(bind=None, **kwargs):
@@ -240,8 +237,6 @@ def clear_mappers():
mapperlib._CONFIGURE_MUTEX.release()
-from . import strategy_options
-
joinedload = strategy_options.joinedload._unbound_fn
joinedload_all = strategy_options.joinedload._unbound_all_fn
contains_eager = strategy_options.contains_eager._unbound_fn
@@ -262,8 +257,6 @@ raiseload = strategy_options.raiseload._unbound_fn
defaultload = strategy_options.defaultload._unbound_fn
selectin_polymorphic = strategy_options.selectin_polymorphic._unbound_fn
-from .strategy_options import Load
-
def eagerload(*args, **kwargs):
"""A synonym for :func:`joinedload()`."""
@@ -280,10 +273,10 @@ contains_alias = public_factory(AliasOption, ".orm.contains_alias")
def __go(lcls):
global __all__
- from .. import util as sa_util
- from . import dynamic
- from . import events
- from . import loading
+ from .. import util as sa_util # noqa
+ from . import dynamic # noqa
+ from . import events # noqa
+ from . import loading # noqa
import inspect as _inspect
__all__ = sorted(
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index 1648c9ae1..b5674d010 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -15,34 +15,38 @@ defines a large part of the ORM's interactivity.
"""
import operator
-from .. import util, event, inspection
-from . import interfaces, collections, exc as orm_exc
-
-from .base import instance_state, instance_dict, manager_of_class
-
-from .base import (
- PASSIVE_NO_RESULT,
- ATTR_WAS_SET,
- ATTR_EMPTY,
- NO_VALUE,
- NEVER_SET,
- NO_CHANGE,
- CALLABLES_OK,
- SQL_OK,
- RELATED_OBJECT_OK,
- INIT_OK,
- NON_PERSISTENT_OK,
- LOAD_AGAINST_COMMITTED,
- PASSIVE_OFF,
- PASSIVE_RETURN_NEVER_SET,
- PASSIVE_NO_INITIALIZE,
- PASSIVE_NO_FETCH,
- PASSIVE_NO_FETCH_RELATED,
- PASSIVE_ONLY_PERSISTENT,
- NO_AUTOFLUSH,
- NO_RAISE,
-)
-from .base import state_str, instance_str
+
+from . import collections
+from . import exc as orm_exc
+from . import interfaces
+from .base import ATTR_EMPTY
+from .base import ATTR_WAS_SET
+from .base import CALLABLES_OK
+from .base import INIT_OK
+from .base import instance_dict
+from .base import instance_state
+from .base import instance_str
+from .base import LOAD_AGAINST_COMMITTED
+from .base import manager_of_class
+from .base import NEVER_SET
+from .base import NO_AUTOFLUSH
+from .base import NO_CHANGE # noqa
+from .base import NO_RAISE
+from .base import NO_VALUE
+from .base import NON_PERSISTENT_OK # noqa
+from .base import PASSIVE_NO_FETCH
+from .base import PASSIVE_NO_FETCH_RELATED # noqa
+from .base import PASSIVE_NO_INITIALIZE
+from .base import PASSIVE_NO_RESULT
+from .base import PASSIVE_OFF
+from .base import PASSIVE_ONLY_PERSISTENT
+from .base import PASSIVE_RETURN_NEVER_SET
+from .base import RELATED_OBJECT_OK # noqa
+from .base import SQL_OK # noqa
+from .base import state_str
+from .. import event
+from .. import inspection
+from .. import util
@inspection._self_inspects
diff --git a/lib/sqlalchemy/orm/base.py b/lib/sqlalchemy/orm/base.py
index abc572d9a..b90a6ca69 100644
--- a/lib/sqlalchemy/orm/base.py
+++ b/lib/sqlalchemy/orm/base.py
@@ -9,11 +9,15 @@
"""
-from .. import util, inspection, exc as sa_exc
-from ..sql import expression
-from . import exc
import operator
+from . import exc
+from .. import exc as sa_exc
+from .. import inspection
+from .. import util
+from ..sql import expression
+
+
PASSIVE_NO_RESULT = util.symbol(
"PASSIVE_NO_RESULT",
"""Symbol returned by a loader callable or other attribute/history
diff --git a/lib/sqlalchemy/orm/collections.py b/lib/sqlalchemy/orm/collections.py
index be9291741..2454f9fae 100644
--- a/lib/sqlalchemy/orm/collections.py
+++ b/lib/sqlalchemy/orm/collections.py
@@ -103,15 +103,15 @@ through the adapter, allowing for some very sophisticated behavior.
"""
-import inspect
import operator
import weakref
-from ..sql import expression
-from .. import util, exc as sa_exc
+from sqlalchemy.util.compat import inspect_getargspec
from . import base
+from .. import exc as sa_exc
+from .. import util
+from ..sql import expression
-from sqlalchemy.util.compat import inspect_getargspec
__all__ = [
"collection",
diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py
index cba4d2141..ed3653de5 100644
--- a/lib/sqlalchemy/orm/dependency.py
+++ b/lib/sqlalchemy/orm/dependency.py
@@ -9,9 +9,17 @@
"""
-from .. import sql, util, exc as sa_exc
-from . import attributes, exc, sync, unitofwork, util as mapperutil
-from .interfaces import ONETOMANY, MANYTOONE, MANYTOMANY
+from . import attributes
+from . import exc
+from . import sync
+from . import unitofwork
+from . import util as mapperutil
+from .interfaces import MANYTOMANY
+from .interfaces import MANYTOONE
+from .interfaces import ONETOMANY
+from .. import exc as sa_exc
+from .. import sql
+from .. import util
class DependencyProcessor(object):
@@ -1180,9 +1188,9 @@ class ManyToManyDP(DependencyProcessor):
)
result = connection.execute(statement, secondary_delete)
- if result.supports_sane_multi_rowcount() and result.rowcount != len(
- secondary_delete
- ):
+ if (
+ result.supports_sane_multi_rowcount()
+ ) and result.rowcount != len(secondary_delete):
raise exc.StaleDataError(
"DELETE statement on table '%s' expected to delete "
"%d row(s); Only %d were matched."
@@ -1206,9 +1214,9 @@ class ManyToManyDP(DependencyProcessor):
)
result = connection.execute(statement, secondary_update)
- if result.supports_sane_multi_rowcount() and result.rowcount != len(
- secondary_update
- ):
+ if (
+ result.supports_sane_multi_rowcount()
+ ) and result.rowcount != len(secondary_update):
raise exc.StaleDataError(
"UPDATE statement on table '%s' expected to update "
"%d row(s); Only %d were matched."
diff --git a/lib/sqlalchemy/orm/deprecated_interfaces.py b/lib/sqlalchemy/orm/deprecated_interfaces.py
index 6b51404d0..0b99ce85d 100644
--- a/lib/sqlalchemy/orm/deprecated_interfaces.py
+++ b/lib/sqlalchemy/orm/deprecated_interfaces.py
@@ -5,8 +5,9 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .. import event, util
from .interfaces import EXT_CONTINUE
+from .. import event
+from .. import util
@util.langhelpers.dependency_for("sqlalchemy.orm.interfaces")
diff --git a/lib/sqlalchemy/orm/descriptor_props.py b/lib/sqlalchemy/orm/descriptor_props.py
index 37517e84c..0891a2a9d 100644
--- a/lib/sqlalchemy/orm/descriptor_props.py
+++ b/lib/sqlalchemy/orm/descriptor_props.py
@@ -11,13 +11,18 @@ as actively in the load/persist ORM loop.
"""
-from .interfaces import MapperProperty, PropComparator
-from .util import _none_set
from . import attributes
-from .. import util, sql, exc as sa_exc, event, schema
-from ..sql import expression
from . import properties
from . import query
+from .interfaces import MapperProperty
+from .interfaces import PropComparator
+from .util import _none_set
+from .. import event
+from .. import exc as sa_exc
+from .. import schema
+from .. import sql
+from .. import util
+from ..sql import expression
class DescriptorProperty(MapperProperty):
@@ -366,10 +371,10 @@ class CompositeProperty(DescriptorProperty):
return self.comparator_factory(self, mapper)
class CompositeBundle(query.Bundle):
- def __init__(self, property, expr):
- self.property = property
+ 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):
diff --git a/lib/sqlalchemy/orm/dynamic.py b/lib/sqlalchemy/orm/dynamic.py
index e5c6b80b6..9665e2485 100644
--- a/lib/sqlalchemy/orm/dynamic.py
+++ b/lib/sqlalchemy/orm/dynamic.py
@@ -12,18 +12,17 @@ basic add/delete mutation.
"""
-from .. import log, util, exc
-from ..sql import operators
-from . import (
- attributes,
- object_session,
- util as orm_util,
- strategies,
- object_mapper,
- exc as orm_exc,
- properties,
-)
+from . import attributes
+from . import exc as orm_exc
+from . import object_mapper
+from . import object_session
+from . import properties
+from . import strategies
+from . import util as orm_util
from .query import Query
+from .. import exc
+from .. import log
+from .. import util
@log.class_logger
diff --git a/lib/sqlalchemy/orm/evaluator.py b/lib/sqlalchemy/orm/evaluator.py
index ac031d84f..2de590748 100644
--- a/lib/sqlalchemy/orm/evaluator.py
+++ b/lib/sqlalchemy/orm/evaluator.py
@@ -6,9 +6,10 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
import operator
-from ..sql import operators
+
from .. import inspect
from .. import util
+from ..sql import operators
class UnevaluatableError(Exception):
diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py
index c2a2d15ee..7c4cfc3ba 100644
--- a/lib/sqlalchemy/orm/events.py
+++ b/lib/sqlalchemy/orm/events.py
@@ -8,17 +8,21 @@
"""ORM event interfaces.
"""
-from .. import event, exc, util
-from .base import _mapper_or_none
-import inspect
import weakref
+
+from . import instrumentation
from . import interfaces
-from . import mapperlib, instrumentation
-from .session import Session, sessionmaker
-from .scoping import scoped_session
+from . import mapperlib
from .attributes import QueryableAttribute
+from .base import _mapper_or_none
from .query import Query
-from sqlalchemy.util.compat import inspect_getargspec
+from .scoping import scoped_session
+from .session import Session
+from .session import sessionmaker
+from .. import event
+from .. import exc
+from .. import util
+from ..util.compat import inspect_getargspec
class InstrumentationEvents(event.Events):
@@ -1885,7 +1889,7 @@ class SessionEvents(event.Events):
class AttributeEvents(event.Events):
- """Define events for object attributes.
+ r"""Define events for object attributes.
These are typically defined on the class-bound descriptor for the
target class.
diff --git a/lib/sqlalchemy/orm/exc.py b/lib/sqlalchemy/orm/exc.py
index f0aa02e99..a8dcf2642 100644
--- a/lib/sqlalchemy/orm/exc.py
+++ b/lib/sqlalchemy/orm/exc.py
@@ -6,7 +6,9 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""SQLAlchemy ORM exceptions."""
-from .. import exc as sa_exc, util
+from .. import exc as sa_exc
+from .. import util
+
NO_STATE = (AttributeError, KeyError)
"""Exception types that may be raised by instrumentation implementations."""
diff --git a/lib/sqlalchemy/orm/identity.py b/lib/sqlalchemy/orm/identity.py
index 2487cdb23..8152c9884 100644
--- a/lib/sqlalchemy/orm/identity.py
+++ b/lib/sqlalchemy/orm/identity.py
@@ -6,10 +6,11 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
import weakref
+
from . import attributes
-from .. import util
-from .. import exc as sa_exc
from . import util as orm_util
+from .. import exc as sa_exc
+from .. import util
class IdentityMap(object):
@@ -32,7 +33,7 @@ class IdentityMap(object):
in the map"""
self.add(state)
- def update(self, dict):
+ def update(self, dict_):
raise NotImplementedError("IdentityMap uses add() to insert data")
def clear(self):
diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py
index fa29c3233..a0fe25357 100644
--- a/lib/sqlalchemy/orm/instrumentation.py
+++ b/lib/sqlalchemy/orm/instrumentation.py
@@ -30,9 +30,12 @@ alternate instrumentation forms.
"""
-from . import exc, collections, interfaces, state
-from .. import util
from . import base
+from . import collections
+from . import exc
+from . import interfaces
+from . import state
+from .. import util
_memoized_key_collection = util.group_expirable_memoized_property()
@@ -69,8 +72,8 @@ class ClassManager(dict):
if mgr is not None
]
- for base in self._bases:
- self.update(base)
+ for base_ in self._bases:
+ self.update(base_)
self.dispatch._events._new_classmanager_instance(class_, self)
# events._InstanceEventsHold.populate(class_, self)
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index d7e70c5d7..5df310db2 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -20,21 +20,23 @@ are exposed when inspecting mappings.
from __future__ import absolute_import
-from .. import util
-from ..sql import operators
-from .base import (
- ONETOMANY,
- MANYTOONE,
- MANYTOMANY,
- EXT_CONTINUE,
- EXT_STOP,
- EXT_SKIP,
- NOT_EXTENSION,
-)
-from .base import InspectionAttr, InspectionAttrInfo, _MappedAttribute
import collections
-from .. import inspect
+
from . import path_registry
+from .base import _MappedAttribute # noqa
+from .base import EXT_CONTINUE
+from .base import EXT_SKIP
+from .base import EXT_STOP
+from .base import InspectionAttr # noqa
+from .base import InspectionAttrInfo # noqa
+from .base import MANYTOMANY
+from .base import MANYTOONE
+from .base import NOT_EXTENSION
+from .base import ONETOMANY
+from .. import inspect
+from .. import util
+from ..sql import operators
+
# imported later
MapperExtension = SessionExtension = AttributeExtension = None
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index 96eddcb32..3662bbe51 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -14,17 +14,20 @@ as well as some of the attribute loading strategies.
"""
from __future__ import absolute_import
+import collections
+
+from . import attributes
+from . import exc as orm_exc
+from . import path_registry
+from . import strategy_options
+from .base import _DEFER_FOR_STATE
+from .base import _SET_DEFERRED_EXPIRED
+from .util import _none_set
+from .util import state_str
+from .. import exc as sa_exc
from .. import util
-from . import attributes, exc as orm_exc
from ..sql import util as sql_util
-from . import strategy_options
-from . import path_registry
-from .. import sql
-from .util import _none_set, state_str
-from .base import _SET_DEFERRED_EXPIRED, _DEFER_FOR_STATE
-from .. import exc as sa_exc
-import collections
_new_runid = util.counter()
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index ea8890788..c0a53694a 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -16,34 +16,39 @@ available in :class:`~sqlalchemy.orm.`.
"""
from __future__ import absolute_import
+from collections import deque
+from itertools import chain
+import sys
import types
import weakref
-from itertools import chain
-from collections import deque
-from .. import sql, util, log, exc as sa_exc, event, schema, inspection
-from ..sql import expression, visitors, operators, util as sql_util
-from . import instrumentation, attributes, exc as orm_exc, loading
+from . import attributes
+from . import exc as orm_exc
+from . import instrumentation
+from . import loading
from . import properties
from . import util as orm_util
-from .interfaces import (
- MapperProperty,
- InspectionAttr,
- _MappedAttribute,
- EXT_SKIP,
-)
-
-
-from .base import (
- _class_to_mapper,
- _state_mapper,
- class_mapper,
- state_str,
- _INSTRUMENTOR,
-)
+from .base import _class_to_mapper
+from .base import _INSTRUMENTOR
+from .base import _state_mapper
+from .base import class_mapper
+from .base import state_str
+from .interfaces import _MappedAttribute
+from .interfaces import EXT_SKIP
+from .interfaces import InspectionAttr
+from .interfaces import MapperProperty
from .path_registry import PathRegistry
-
-import sys
+from .. import event
+from .. import exc as sa_exc
+from .. import inspection
+from .. import log
+from .. import schema
+from .. import sql
+from .. import util
+from ..sql import expression
+from ..sql import operators
+from ..sql import util as sql_util
+from ..sql import visitors
_mapper_registry = weakref.WeakKeyDictionary()
@@ -1087,7 +1092,7 @@ class Mapper(InspectionAttr):
self.polymorphic_map[self.polymorphic_identity] = self
if self.polymorphic_load and self.concrete:
- raise exc.ArgumentError(
+ raise sa_exc.ArgumentError(
"polymorphic_load is not currently supported "
"with concrete table inheritance"
)
@@ -1615,9 +1620,9 @@ class Mapper(InspectionAttr):
if self.mapped_table is mapper.mapped_table:
self.polymorphic_on = mapper.polymorphic_on
else:
- self.polymorphic_on = self.mapped_table.corresponding_column(
- mapper.polymorphic_on
- )
+ self.polymorphic_on = (
+ self.mapped_table.corresponding_column
+ )(mapper.polymorphic_on)
# we can use the parent mapper's _set_polymorphic_identity
# directly; it ensures the polymorphic_identity of the
# instance's mapper is used so is portable to subclasses.
@@ -2485,7 +2490,7 @@ class Mapper(InspectionAttr):
@_memoized_configured_property
def _equivalent_columns(self):
- """Create a map of all *equivalent* columns, based on
+ """Create a map of all equivalent columns, based on
the determination of column pairs that are equated to
one another based on inherit condition. This is designed
to work with the queries that util.polymorphic_union
@@ -2494,14 +2499,14 @@ class Mapper(InspectionAttr):
only).
The resulting structure is a dictionary of columns mapped
- to lists of equivalent columns, i.e.
+ to lists of equivalent columns, e.g.::
- {
- tablea.col1:
- {tableb.col1, tablec.col1},
- tablea.col2:
- {tabled.col2}
- }
+ {
+ tablea.col1:
+ {tableb.col1, tablec.col1},
+ tablea.col2:
+ {tabled.col2}
+ }
"""
result = util.column_dict()
@@ -3026,10 +3031,18 @@ class Mapper(InspectionAttr):
if queue:
visitables.append((queue, mpp, None, None))
elif item_type is mpp:
- instance, instance_mapper, corresponding_state, corresponding_dict = (
- iterator.popleft()
+ (
+ instance,
+ instance_mapper,
+ corresponding_state,
+ corresponding_dict,
+ ) = iterator.popleft()
+ yield (
+ instance,
+ instance_mapper,
+ corresponding_state,
+ corresponding_dict,
)
- yield instance, instance_mapper, corresponding_state, corresponding_dict
visitables.append(
(
deque(instance_mapper._props.values()),
diff --git a/lib/sqlalchemy/orm/path_registry.py b/lib/sqlalchemy/orm/path_registry.py
index f33c209cc..97f15d9f6 100644
--- a/lib/sqlalchemy/orm/path_registry.py
+++ b/lib/sqlalchemy/orm/path_registry.py
@@ -8,13 +8,15 @@
"""
-from .. import inspection
-from .. import util
-from .. import exc
from itertools import chain
-from .base import class_mapper
import logging
+from .base import class_mapper
+from .. import exc
+from .. import inspection
+from .. import util
+
+
log = logging.getLogger(__name__)
diff --git a/lib/sqlalchemy/orm/persistence.py b/lib/sqlalchemy/orm/persistence.py
index dc86a60e5..9e96cda42 100644
--- a/lib/sqlalchemy/orm/persistence.py
+++ b/lib/sqlalchemy/orm/persistence.py
@@ -14,14 +14,22 @@ in unitofwork.py.
"""
+from itertools import chain
+from itertools import groupby
import operator
-from itertools import groupby, chain
-from .. import sql, util, exc as sa_exc
-from . import attributes, sync, exc as orm_exc, evaluator
-from .base import state_str, _entity_descriptor
+
+from . import attributes
+from . import evaluator
+from . import exc as orm_exc
+from . import loading
+from . import sync
+from .base import _entity_descriptor
+from .base import state_str
+from .. import exc as sa_exc
+from .. import sql
+from .. import util
from ..sql import expression
from ..sql.base import _from_objects
-from . import loading
def _bulk_insert(
@@ -67,7 +75,16 @@ def _bulk_insert(
has_all_pks,
has_all_defaults,
)
- for state, state_dict, params, mp, conn, value_params, has_all_pks, has_all_defaults in _collect_insert_commands(
+ for (
+ state,
+ state_dict,
+ params,
+ mp,
+ conn,
+ value_params,
+ has_all_pks,
+ has_all_defaults,
+ ) in _collect_insert_commands(
table,
((None, mapping, mapper, connection) for mapping in mappings),
bulk=True,
@@ -234,11 +251,17 @@ def save_obj(base_mapper, states, uowtransaction, single=False):
chain(
(
(state, state_dict, mapper, connection, False)
- for state, state_dict, mapper, connection in states_to_insert
+ for (state, state_dict, mapper, connection) in states_to_insert
),
(
(state, state_dict, mapper, connection, True)
- for state, state_dict, mapper, connection, update_version_id in states_to_update
+ for (
+ state,
+ state_dict,
+ mapper,
+ connection,
+ update_version_id,
+ ) in states_to_update
),
),
)
@@ -609,9 +632,9 @@ def _collect_update_commands(
params[col.key] = value
if mapper.base_mapper.eager_defaults:
- has_all_defaults = mapper._server_onupdate_default_cols[
- table
- ].issubset(params)
+ has_all_defaults = (
+ mapper._server_onupdate_default_cols[table]
+ ).issubset(params)
else:
has_all_defaults = True
diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py
index a39cd8703..3ea68a913 100644
--- a/lib/sqlalchemy/orm/properties.py
+++ b/lib/sqlalchemy/orm/properties.py
@@ -13,12 +13,14 @@ mapped attributes.
"""
from __future__ import absolute_import
-from .. import util, log
-from ..sql import expression
from . import attributes
+from .interfaces import PropComparator
+from .interfaces import StrategizedProperty
from .util import _orm_full_deannotate
+from .. import log
+from .. import util
+from ..sql import expression
-from .interfaces import PropComparator, StrategizedProperty
__all__ = ["ColumnProperty"]
@@ -213,9 +215,9 @@ class ColumnProperty(StrategizedProperty):
util.warn(
(
"On mapper %s, primary key column '%s' is being combined "
- "with distinct primary key column '%s' in attribute '%s'. "
- "Use explicit properties to give each column its own mapped "
- "attribute name."
+ "with distinct primary key column '%s' in attribute '%s'. "
+ "Use explicit properties to give each column its own "
+ "mapped attribute name."
)
% (self.parent, self.columns[1], self.columns[0], self.key)
)
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py
index 4a55a3247..a4dddcd23 100644
--- a/lib/sqlalchemy/orm/query.py
+++ b/lib/sqlalchemy/orm/query.py
@@ -21,36 +21,39 @@ database to return iterable result sets.
from itertools import chain
-from . import (
- attributes,
- interfaces,
- object_mapper,
- persistence,
- exc as orm_exc,
- loading,
-)
-from .base import (
- _entity_descriptor,
- _is_aliased_class,
- _is_mapped_class,
- _orm_columns,
- _generative,
- InspectionAttr,
-)
+from . import attributes
+from . import exc as orm_exc
+from . import interfaces
+from . import loading
+from . import persistence
+from . import properties
+from .base import _entity_descriptor
+from .base import _generative
+from .base import _is_aliased_class
+from .base import _is_mapped_class
+from .base import _orm_columns
+from .base import InspectionAttr
from .path_registry import PathRegistry
-from .util import (
- AliasedClass,
- ORMAdapter,
- join as orm_join,
- with_parent,
- aliased,
- _entity_corresponds_to,
-)
-from .. import sql, util, log, exc as sa_exc, inspect, inspection
-from ..sql.expression import _interpret_as_from
-from ..sql import util as sql_util, expression, visitors
+from .util import _entity_corresponds_to
+from .util import aliased
+from .util import AliasedClass
+from .util import join as orm_join
+from .util import object_mapper
+from .util import ORMAdapter
+from .util import with_parent
+from .. import exc as sa_exc
+from .. import inspect
+from .. import inspection
+from .. import log
+from .. import sql
+from .. import util
+from ..sql import expression
+from ..sql import util as sql_util
+from ..sql import visitors
from ..sql.base import ColumnCollection
-from . import properties
+from ..sql.expression import _interpret_as_from
+from ..sql.selectable import ForUpdateArg
+
__all__ = ["Query", "QueryContext", "aliased"]
@@ -1103,7 +1106,7 @@ class Query(object):
"""
self._invoke_all_eagers = value
- def with_parent(self, instance, property=None, from_entity=None):
+ def with_parent(self, instance, property=None, from_entity=None): # noqa
"""Add filtering criterion that relates the given instance
to a child object or collection, using its attribute state
as well as an established :func:`.relationship()`
@@ -1143,7 +1146,7 @@ class Query(object):
isinstance(prop, properties.RelationshipProperty)
and prop.mapper is entity_zero.mapper
):
- property = prop
+ property = prop # noqa
break
else:
raise sa_exc.InvalidRequestError(
@@ -2397,17 +2400,20 @@ class Query(object):
# figure out the best "left" side based on our existing froms /
# entities
assert prop is None
- left, replace_from_obj_index, use_entity_index = self._join_determine_implicit_left_side(
- left, right, onclause
- )
+ (
+ left,
+ replace_from_obj_index,
+ use_entity_index,
+ ) = self._join_determine_implicit_left_side(left, right, onclause)
else:
# left is given via a relationship/name. Determine where in our
# "froms" list it should be spliced/appended as well as what
# existing entity it corresponds to.
assert prop is not None
- replace_from_obj_index, use_entity_index = self._join_place_explicit_left_side(
- left
- )
+ (
+ replace_from_obj_index,
+ use_entity_index,
+ ) = self._join_place_explicit_left_side(left)
# this should never happen because we would not have found a place
# to join on
@@ -3153,7 +3159,8 @@ class Query(object):
(note this may consist of multiple result rows if join-loaded
collections are present).
- Calling :meth:`.Query.first` results in an execution of the underlying query.
+ Calling :meth:`.Query.first` results in an execution of the underlying
+ query.
.. seealso::
@@ -3665,7 +3672,8 @@ class Query(object):
values or sql expressions as values. If :ref:`parameter-ordered
mode <updates_order_parameters>` is desired, the values can be
passed as a list of 2-tuples;
- this requires that the :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order`
+ this requires that the
+ :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order`
flag is passed to the :paramref:`.Query.update.update_args` dictionary
as well.
@@ -3905,9 +3913,9 @@ class Query(object):
context.order_by = None
if self._distinct is True and context.order_by:
- context.primary_columns += sql_util.expand_column_list_from_order_by(
- context.primary_columns, context.order_by
- )
+ context.primary_columns += (
+ sql_util.expand_column_list_from_order_by
+ )(context.primary_columns, context.order_by)
context.froms += tuple(context.eager_joins.values())
statement = sql.select(
@@ -3966,9 +3974,6 @@ class Query(object):
)
-from ..sql.selectable import ForUpdateArg
-
-
class LockmodeArg(ForUpdateArg):
@classmethod
def parse_legacy_query(self, mode):
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py
index e89d1542f..27a8c4ca9 100644
--- a/lib/sqlalchemy/orm/relationships.py
+++ b/lib/sqlalchemy/orm/relationships.py
@@ -14,34 +14,38 @@ and `secondaryjoin` aspects of :func:`.relationship`.
"""
from __future__ import absolute_import
-from .. import sql, util, exc as sa_exc, schema, log
+import collections
import weakref
-from .util import CascadeOptions, _orm_annotate, _orm_deannotate
-from . import dependency
+
from . import attributes
-from ..sql.util import (
- ClauseAdapter,
- join_condition,
- _shallow_annotate,
- visit_binary_product,
- _deep_deannotate,
- selectables_overlap,
- adapt_criterion_to_null,
-)
+from . import dependency
+from . import mapper as mapperlib
from .base import state_str
-
-from ..sql import operators, expression, visitors
-from .interfaces import (
- MANYTOMANY,
- MANYTOONE,
- ONETOMANY,
- StrategizedProperty,
- PropComparator,
-)
+from .interfaces import MANYTOMANY
+from .interfaces import MANYTOONE
+from .interfaces import ONETOMANY
+from .interfaces import PropComparator
+from .interfaces import StrategizedProperty
+from .util import _orm_annotate
+from .util import _orm_deannotate
+from .util import CascadeOptions
+from .. import exc as sa_exc
+from .. import log
+from .. import schema
+from .. import sql
+from .. import util
from ..inspection import inspect
-from . import mapper as mapperlib
-import collections
+from ..sql import expression
+from ..sql import operators
+from ..sql import visitors
+from ..sql.util import _deep_deannotate
+from ..sql.util import _shallow_annotate
+from ..sql.util import adapt_criterion_to_null
+from ..sql.util import ClauseAdapter
+from ..sql.util import join_condition
+from ..sql.util import selectables_overlap
+from ..sql.util import visit_binary_product
def remote(expr):
@@ -88,7 +92,7 @@ def foreign(expr):
@log.class_logger
-@util.langhelpers.dependency_for("sqlalchemy.orm.properties")
+@util.langhelpers.dependency_for("sqlalchemy.orm.properties", add_to_all=True)
class RelationshipProperty(StrategizedProperty):
"""Describes an object property that holds a single item or list
of items that correspond to a related database table.
@@ -596,8 +600,8 @@ class RelationshipProperty(StrategizedProperty):
.. seealso::
- :doc:`/orm/loading_relationships` - Full documentation on relationship loader
- configuration.
+ :doc:`/orm/loading_relationships` - Full documentation on
+ relationship loader configuration.
:ref:`dynamic_relationship` - detail on the ``dynamic`` option.
@@ -991,7 +995,14 @@ class RelationshipProperty(StrategizedProperty):
else:
of_type = None
- pj, sj, source, dest, secondary, target_adapter = self.property._create_joins(
+ (
+ pj,
+ sj,
+ source,
+ dest,
+ secondary,
+ target_adapter,
+ ) = self.property._create_joins(
source_selectable=adapt_from,
source_polymorphic=True,
of_type=of_type,
@@ -1112,7 +1123,14 @@ class RelationshipProperty(StrategizedProperty):
else:
source_selectable = None
- pj, sj, source, dest, secondary, target_adapter = self.property._create_joins(
+ (
+ pj,
+ sj,
+ source,
+ dest,
+ secondary,
+ target_adapter,
+ ) = self.property._create_joins(
dest_polymorphic=True,
dest_selectable=to_selectable,
source_selectable=source_selectable,
@@ -1508,7 +1526,7 @@ class RelationshipProperty(StrategizedProperty):
Above, the SQL should be "address.user_id = 5". The callable
returned by this method produces the value "5" based on the identity
- of ``u1`.
+ of ``u1``.
"""
@@ -2108,9 +2126,9 @@ class RelationshipProperty(StrategizedProperty):
if self.uselist is None:
self.uselist = self.direction is not MANYTOONE
if not self.viewonly:
- self._dependency_processor = dependency.DependencyProcessor.from_relationship(
- self
- )
+ self._dependency_processor = (
+ dependency.DependencyProcessor.from_relationship
+ )(self)
@util.memoized_property
def _use_get(self):
@@ -2155,7 +2173,13 @@ class RelationshipProperty(StrategizedProperty):
single_crit = dest_mapper._single_table_criterion
aliased = aliased or (source_selectable is not None)
- primaryjoin, secondaryjoin, secondary, target_adapter, dest_selectable = self._join_condition.join_targets(
+ (
+ primaryjoin,
+ secondaryjoin,
+ secondary,
+ target_adapter,
+ dest_selectable,
+ ) = self._join_condition.join_targets(
source_selectable, dest_selectable, aliased, single_crit
)
if source_selectable is None:
diff --git a/lib/sqlalchemy/orm/scoping.py b/lib/sqlalchemy/orm/scoping.py
index 2eeaf5b6d..fea0b1de8 100644
--- a/lib/sqlalchemy/orm/scoping.py
+++ b/lib/sqlalchemy/orm/scoping.py
@@ -5,10 +5,13 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .. import exc as sa_exc
-from ..util import ScopedRegistry, ThreadLocalRegistry, warn
-from . import class_mapper, exc as orm_exc
+from . import class_mapper
+from . import exc as orm_exc
from .session import Session
+from .. import exc as sa_exc
+from ..util import ScopedRegistry
+from ..util import ThreadLocalRegistry
+from ..util import warn
__all__ = ["scoped_session"]
@@ -166,13 +169,13 @@ for meth in Session.public_methods:
def makeprop(name):
- def set(self, attr):
+ def set_(self, attr):
setattr(self.registry(), name, attr)
def get(self):
return getattr(self.registry(), name)
- return property(get, set)
+ return property(get, set_)
for prop in (
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index a3edacc19..d226edf81 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -7,26 +7,34 @@
"""Provides the Session class and related utilities."""
-import weakref
-from .. import util, sql, engine, exc as sa_exc
-from ..sql import util as sql_util, expression
-from . import SessionExtension, attributes, exc, query, loading, identity
-from ..inspection import inspect
-from .base import (
- object_mapper,
- class_mapper,
- _class_to_mapper,
- _state_mapper,
- object_state,
- _none_set,
- state_str,
- instance_str,
-)
import itertools
+import sys
+import weakref
+
+from . import attributes
+from . import exc
+from . import identity
+from . import loading
from . import persistence
-from .unitofwork import UOWTransaction
+from . import query
from . import state as statelib
-import sys
+from .base import _class_to_mapper
+from .base import _none_set
+from .base import _state_mapper
+from .base import instance_str
+from .base import object_mapper
+from .base import object_state
+from .base import state_str
+from .deprecated_interfaces import SessionExtension
+from .unitofwork import UOWTransaction
+from .. import engine
+from .. import exc as sa_exc
+from .. import sql
+from .. import util
+from ..inspection import inspect
+from ..sql import expression
+from ..sql import util as sql_util
+
__all__ = ["Session", "SessionTransaction", "SessionExtension", "sessionmaker"]
@@ -578,11 +586,11 @@ class SessionTransaction(object):
def __enter__(self):
return self
- def __exit__(self, type, value, traceback):
+ def __exit__(self, type_, value, traceback):
self._assert_active(deactive_ok=True, prepared_ok=True)
if self.session.transaction is None:
return
- if type is None:
+ if type_ is None:
try:
self.commit()
except:
@@ -888,9 +896,10 @@ class Session(_SessionClassMethods):
:param subtransactions: if True, indicates that this
:meth:`~.Session.begin` can create a "subtransaction".
- :param nested: if True, begins a SAVEPOINT transaction and is equivalent
- to calling :meth:`~.Session.begin_nested`. For documentation on
- SAVEPOINT transactions, please see :ref:`session_begin_nested`.
+ :param nested: if True, begins a SAVEPOINT transaction and is
+ equivalent to calling :meth:`~.Session.begin_nested`. For
+ documentation on SAVEPOINT transactions, please see
+ :ref:`session_begin_nested`.
:return: the :class:`.SessionTransaction` object. Note that
:class:`.SessionTransaction`
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index c36d8817b..6e539a3be 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -13,22 +13,22 @@ defines a large part of the ORM's interactivity.
"""
import weakref
-from .. import util
-from .. import inspection
-from .. import exc as sa_exc
-from . import exc as orm_exc, interfaces
-from .path_registry import PathRegistry
-from .base import (
- PASSIVE_NO_RESULT,
- SQL_OK,
- NEVER_SET,
- ATTR_WAS_SET,
- NO_VALUE,
- PASSIVE_NO_INITIALIZE,
- INIT_OK,
- PASSIVE_OFF,
-)
+
from . import base
+from . import exc as orm_exc
+from . import interfaces
+from .base import ATTR_WAS_SET
+from .base import INIT_OK
+from .base import NEVER_SET
+from .base import NO_VALUE
+from .base import PASSIVE_NO_INITIALIZE
+from .base import PASSIVE_NO_RESULT
+from .base import PASSIVE_OFF
+from .base import SQL_OK
+from .path_registry import PathRegistry
+from .. import exc as sa_exc
+from .. import inspection
+from .. import util
@inspection._self_inspects
@@ -157,8 +157,9 @@ class InstanceState(interfaces.InspectionAttrInfo):
"detached" states; once the object is :term:`detached`, the
:attr:`.InstanceState.deleted` attribute **no longer returns
True**; in order to detect that a state was deleted, regardless
- of whether or not the object is associated with a :class:`.Session`,
- use the :attr:`.InstanceState.was_deleted` accessor.
+ of whether or not the object is associated with a
+ :class:`.Session`, use the :attr:`.InstanceState.was_deleted`
+ accessor.
.. versionadded: 1.1
@@ -815,10 +816,10 @@ class InstanceState(interfaces.InspectionAttrInfo):
self._commit_all_states([(self, dict_)], instance_dict)
@classmethod
- def _commit_all_states(self, iter, instance_dict=None):
+ def _commit_all_states(self, iter_, instance_dict=None):
"""Mass / highly inlined version of commit_all()."""
- for state, dict_ in iter:
+ for state, dict_ in iter_:
state_dict = state.__dict__
state.committed_state.clear()
diff --git a/lib/sqlalchemy/orm/strategies.py b/lib/sqlalchemy/orm/strategies.py
index 5c972b26b..afa91d876 100644
--- a/lib/sqlalchemy/orm/strategies.py
+++ b/lib/sqlalchemy/orm/strategies.py
@@ -8,26 +8,32 @@
"""sqlalchemy.orm.interfaces.LoaderStrategy
implementations, and related MapperOptions."""
-from .. import exc as sa_exc, inspect
-from .. import util, log, event
-from ..sql import util as sql_util, visitors
-from .. import sql
-from . import (
- attributes,
- interfaces,
- exc as orm_exc,
- loading,
- unitofwork,
- util as orm_util,
- query,
-)
-from .state import InstanceState
-from .util import _none_set, aliased
+import itertools
+
+from . import attributes
+from . import exc as orm_exc
+from . import interfaces
+from . import loading
from . import properties
-from .interfaces import LoaderStrategy, StrategizedProperty
-from .base import _SET_DEFERRED_EXPIRED, _DEFER_FOR_STATE
+from . import query
+from . import unitofwork
+from . import util as orm_util
+from .base import _DEFER_FOR_STATE
+from .base import _SET_DEFERRED_EXPIRED
+from .interfaces import LoaderStrategy
+from .interfaces import StrategizedProperty
from .session import _state_session
-import itertools
+from .state import InstanceState
+from .util import _none_set
+from .util import aliased
+from .. import event
+from .. import exc as sa_exc
+from .. import inspect
+from .. import log
+from .. import sql
+from .. import util
+from ..sql import util as sql_util
+from ..sql import visitors
def _register_attribute(
@@ -524,9 +530,11 @@ class LazyLoader(AbstractRelationshipLoader, util.MemoizedSlots):
join_condition.create_lazy_clause()
)
- self._rev_lazywhere, self._rev_bind_to_col, self._rev_equated_columns = join_condition.create_lazy_clause(
- reverse_direction=True
- )
+ (
+ self._rev_lazywhere,
+ self._rev_bind_to_col,
+ self._rev_equated_columns,
+ ) = join_condition.create_lazy_clause(reverse_direction=True)
self.logger.info("%s lazy loading clause %s", self, self._lazywhere)
@@ -875,9 +883,9 @@ class LazyLoader(AbstractRelationshipLoader, util.MemoizedSlots):
# "lazyload" option on a "no load"
# attribute - "eager" attributes always have a
# class-level lazyloader installed.
- set_lazy_callable = InstanceState._instance_level_callable_processor(
- mapper.class_manager, LoadLazyAttribute(key, self), key
- )
+ set_lazy_callable = (
+ InstanceState._instance_level_callable_processor
+ )(mapper.class_manager, LoadLazyAttribute(key, self), key)
populators["new"].append((self.key, set_lazy_callable))
elif context.populate_existing or mapper.always_refresh:
@@ -1008,9 +1016,11 @@ class SubqueryLoader(AbstractRelationshipLoader):
elif subq_path.contains_mapper(self.mapper):
return
- leftmost_mapper, leftmost_attr, leftmost_relationship = self._get_leftmost(
- subq_path
- )
+ (
+ leftmost_mapper,
+ leftmost_attr,
+ leftmost_relationship,
+ ) = self._get_leftmost(subq_path)
orig_query = context.attributes.get(
("orig_query", SubqueryLoader), context.query
@@ -1439,7 +1449,11 @@ class JoinedLoader(AbstractRelationshipLoader):
)
if user_defined_adapter is not False:
- clauses, adapter, add_to_collection = self._setup_query_on_user_defined_adapter(
+ (
+ clauses,
+ adapter,
+ add_to_collection,
+ ) = self._setup_query_on_user_defined_adapter(
context, entity, path, adapter, user_defined_adapter
)
else:
@@ -1452,7 +1466,12 @@ class JoinedLoader(AbstractRelationshipLoader):
elif path.contains_mapper(self.mapper):
return
- clauses, adapter, add_to_collection, chained_from_outerjoin = self._generate_row_adapter(
+ (
+ clauses,
+ adapter,
+ add_to_collection,
+ chained_from_outerjoin,
+ ) = self._generate_row_adapter(
context,
entity,
path,
@@ -1795,9 +1814,9 @@ class JoinedLoader(AbstractRelationshipLoader):
context.primary_columns.append(col)
if self.parent_property.order_by:
- context.eager_order_by += eagerjoin._target_adapter.copy_and_process(
- util.to_list(self.parent_property.order_by)
- )
+ context.eager_order_by += (
+ eagerjoin._target_adapter.copy_and_process
+ )(util.to_list(self.parent_property.order_by))
def _splice_nested_inner_join(
self, path, join_obj, clauses, onclause, splicing=False
@@ -2228,10 +2247,12 @@ class SelectInLoader(AbstractRelationshipLoader, util.MemoizedSlots):
# imitate the same method that subquery eager loading uses,
# looking for the adapted "secondary" table
eagerjoin = q._from_obj[0]
- eager_order_by = eagerjoin._target_adapter.copy_and_process(
- util.to_list(self.parent_property.order_by)
+
+ return q.order_by(
+ *eagerjoin._target_adapter.copy_and_process(
+ util.to_list(self.parent_property.order_by)
+ )
)
- return q.order_by(*eager_order_by)
q.add_criteria(_setup_outermost_orderby)
diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py
index b2f6bcb11..2d0716991 100644
--- a/lib/sqlalchemy/orm/strategy_options.py
+++ b/lib/sqlalchemy/orm/strategy_options.py
@@ -8,24 +8,25 @@
"""
-from .interfaces import MapperOption, PropComparator, MapperProperty
+from . import util as orm_util
from .attributes import QueryableAttribute
+from .base import _class_to_mapper
+from .base import _is_aliased_class
+from .base import _is_mapped_class
+from .base import InspectionAttr
+from .interfaces import MapperOption
+from .interfaces import PropComparator
+from .path_registry import _DEFAULT_TOKEN
+from .path_registry import _WILDCARD_TOKEN
+from .path_registry import PathRegistry
+from .path_registry import TokenRegistry
+from .util import _orm_full_deannotate
+from .. import exc as sa_exc
+from .. import inspect
from .. import util
-from ..sql.base import _generative, Generative
-from .. import exc as sa_exc, inspect
-from .base import (
- _is_aliased_class,
- _class_to_mapper,
- _is_mapped_class,
- InspectionAttr,
-)
-from . import util as orm_util
-from .path_registry import (
- PathRegistry,
- TokenRegistry,
- _WILDCARD_TOKEN,
- _DEFAULT_TOKEN,
-)
+from ..sql import expression as sql_expr
+from ..sql.base import _generative
+from ..sql.base import Generative
class Load(Generative, MapperOption):
@@ -1454,10 +1455,6 @@ def undefer_group(name):
return _UnboundLoad().undefer_group(name)
-from ..sql import expression as sql_expr
-from .util import _orm_full_deannotate
-
-
@loader_option()
def with_expression(loadopt, key, expression):
r"""Apply an ad-hoc SQL expression to a "deferred expression" attribute.
diff --git a/lib/sqlalchemy/orm/sync.py b/lib/sqlalchemy/orm/sync.py
index 0cd488cbd..2134b6dbf 100644
--- a/lib/sqlalchemy/orm/sync.py
+++ b/lib/sqlalchemy/orm/sync.py
@@ -10,7 +10,9 @@ between instances based on join conditions.
"""
-from . import exc, util as orm_util, attributes
+from . import attributes
+from . import exc
+from . import util as orm_util
def populate(
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py
index 545811bb4..0d1dae8fc 100644
--- a/lib/sqlalchemy/orm/unitofwork.py
+++ b/lib/sqlalchemy/orm/unitofwork.py
@@ -13,11 +13,13 @@ organizes them in order of dependency, and executes.
"""
-from .. import util, event
-from ..util import topological
-from . import attributes, persistence, util as orm_util
+from . import attributes
from . import exc as orm_exc
-import itertools
+from . import persistence
+from . import util as orm_util
+from .. import event
+from .. import util
+from ..util import topological
def track_cascade_events(descriptor, prop):
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py
index a1b0cd5da..4a1e18c1a 100644
--- a/lib/sqlalchemy/orm/util.py
+++ b/lib/sqlalchemy/orm/util.py
@@ -6,26 +6,32 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .. import sql, util, event, exc as sa_exc, inspection
-from ..sql import expression, util as sql_util, operators
-from .interfaces import PropComparator, MapperProperty
-from . import attributes
import re
-from .base import (
- instance_str,
- state_str,
- state_class_str,
- attribute_str,
- state_attribute_str,
- object_mapper,
- object_state,
- _none_set,
- _never_set,
-)
-from .base import class_mapper, _class_to_mapper
-from .base import InspectionAttr
-from .path_registry import PathRegistry
+from . import attributes # noqa
+from .base import _class_to_mapper # noqa
+from .base import _never_set # noqa
+from .base import _none_set # noqa
+from .base import attribute_str # noqa
+from .base import class_mapper # noqa
+from .base import InspectionAttr # noqa
+from .base import instance_str # noqa
+from .base import object_mapper # noqa
+from .base import object_state # noqa
+from .base import state_attribute_str # noqa
+from .base import state_class_str # noqa
+from .base import state_str # noqa
+from .interfaces import MapperProperty # noqa
+from .interfaces import PropComparator # noqa
+from .path_registry import PathRegistry # noqa
+from .. import event
+from .. import exc as sa_exc
+from .. import inspection
+from .. import sql
+from .. import util
+from ..sql import expression
+from ..sql import util as sql_util
+
all_cascades = frozenset(
(
@@ -221,14 +227,14 @@ def polymorphic_union(
return sql.type_coerce(sql.null(), types[name]).label(name)
result = []
- for type, table in table_map.items():
+ for type_, table in table_map.items():
if typecolname is not None:
result.append(
sql.select(
[col(name, table) for name in colnames]
+ [
sql.literal_column(
- sql_util._quote_ddl_expr(type)
+ sql_util._quote_ddl_expr(type_)
).label(typecolname)
],
from_obj=[table],
@@ -261,7 +267,7 @@ def identity_key(*args, **kwargs):
:param class: mapped class (must be a positional argument)
:param ident: primary key, may be a scalar or tuple argument.
- ;param identity_token: optional identity token
+ :param identity_token: optional identity token
.. versionadded:: 1.2 added identity_token
@@ -301,7 +307,7 @@ first()
:param class: mapped class (must be a positional argument)
:param row: :class:`.RowProxy` row returned by a :class:`.ResultProxy`
(must be given as a keyword arg)
- ;param identity_token: optional identity token
+ :param identity_token: optional identity token
.. versionadded:: 1.2 added identity_token
@@ -957,7 +963,14 @@ class _ORMJoin(expression.Join):
else:
adapt_from = left_info.selectable
- pj, sj, source, dest, secondary, target_adapter = prop._create_joins(
+ (
+ pj,
+ sj,
+ source,
+ dest,
+ secondary,
+ target_adapter,
+ ) = prop._create_joins(
source_selectable=adapt_from,
dest_selectable=adapt_to,
source_polymorphic=True,
@@ -1125,7 +1138,7 @@ def with_parent(instance, prop, from_entity=None):
return prop._with_parent(instance, from_entity=from_entity)
-def has_identity(object):
+def has_identity(object_):
"""Return True if the given object has a database
identity.
@@ -1137,11 +1150,11 @@ def has_identity(object):
:func:`.was_deleted`
"""
- state = attributes.instance_state(object)
+ state = attributes.instance_state(object_)
return state.has_identity
-def was_deleted(object):
+def was_deleted(object_):
"""Return True if the given object was deleted
within a session flush.
@@ -1156,7 +1169,7 @@ def was_deleted(object):
"""
- state = attributes.instance_state(object)
+ state = attributes.instance_state(object_)
return state.was_deleted
diff --git a/lib/sqlalchemy/pool/__init__.py b/lib/sqlalchemy/pool/__init__.py
index 2aa6eeeb7..39017906c 100644
--- a/lib/sqlalchemy/pool/__init__.py
+++ b/lib/sqlalchemy/pool/__init__.py
@@ -17,19 +17,36 @@ regular DB-API connect() methods to be transparently managed by a
SQLAlchemy connection pool.
"""
+from .base import _ConnectionFairy # noqa
+from .base import _ConnectionRecord # noqa
+from .base import _finalize_fairy # noqa
from .base import _refs # noqa
-from .base import Pool # noqa
-from .impl import ( # noqa
- QueuePool,
- StaticPool,
- NullPool,
- AssertionPool,
- SingletonThreadPool,
-)
-from .dbapi_proxy import manage, clear_managers # noqa
-
-from .base import reset_rollback, reset_commit, reset_none # noqa
+from .base import Pool
+from .base import reset_commit
+from .base import reset_none
+from .base import reset_rollback
+from .dbapi_proxy import clear_managers
+from .dbapi_proxy import manage
+from .impl import AssertionPool
+from .impl import NullPool
+from .impl import QueuePool
+from .impl import SingletonThreadPool
+from .impl import StaticPool
+
+
+__all__ = [
+ "Pool",
+ "reset_commit",
+ "reset_none",
+ "reset_rollback",
+ "clear_managers",
+ "manage",
+ "AssertionPool",
+ "NullPool",
+ "QueuePool",
+ "SingletonThreadPool",
+ "StaticPool",
+]
# as these are likely to be used in various test suites, debugging
# setups, keep them in the sqlalchemy.pool namespace
-from .base import _ConnectionFairy, _ConnectionRecord, _finalize_fairy # noqa
diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py
index 382e740c6..8df0b89c6 100644
--- a/lib/sqlalchemy/pool/base.py
+++ b/lib/sqlalchemy/pool/base.py
@@ -14,7 +14,11 @@ from collections import deque
import time
import weakref
-from .. import exc, log, event, interfaces, util
+from .. import event
+from .. import exc
+from .. import interfaces
+from .. import log
+from .. import util
from ..util import threading
diff --git a/lib/sqlalchemy/pool/dbapi_proxy.py b/lib/sqlalchemy/pool/dbapi_proxy.py
index 425c4a114..ccd157948 100644
--- a/lib/sqlalchemy/pool/dbapi_proxy.py
+++ b/lib/sqlalchemy/pool/dbapi_proxy.py
@@ -18,6 +18,7 @@ today.
from .impl import QueuePool
from ..util import threading
+
proxies = {}
diff --git a/lib/sqlalchemy/pool/impl.py b/lib/sqlalchemy/pool/impl.py
index 6159f6a5b..d1b038d47 100644
--- a/lib/sqlalchemy/pool/impl.py
+++ b/lib/sqlalchemy/pool/impl.py
@@ -13,11 +13,12 @@
import traceback
import weakref
-from .base import Pool, _ConnectionRecord
+from .base import _ConnectionRecord
+from .base import Pool
from .. import exc
from .. import util
-from ..util import queue as sqla_queue
from ..util import chop_traceback
+from ..util import queue as sqla_queue
from ..util import threading
diff --git a/lib/sqlalchemy/processors.py b/lib/sqlalchemy/processors.py
index 46d5dcbc6..74a2fe54e 100644
--- a/lib/sqlalchemy/processors.py
+++ b/lib/sqlalchemy/processors.py
@@ -14,8 +14,9 @@ They all share one common characteristic: None is passed through unchanged.
"""
import codecs
-import re
import datetime
+import re
+
from . import util
@@ -101,19 +102,19 @@ def py_fallback():
return process
- def to_float(value):
+ def to_float(value): # noqa
if value is None:
return None
else:
return float(value)
- def to_str(value):
+ def to_str(value): # noqa
if value is None:
return None
else:
return str(value)
- def int_to_boolean(value):
+ def int_to_boolean(value): # noqa
if value is None:
return None
else:
@@ -125,25 +126,27 @@ def py_fallback():
TIME_RE = re.compile(r"(\d+):(\d+):(\d+)(?:\.(\d+))?")
DATE_RE = re.compile(r"(\d+)-(\d+)-(\d+)")
- str_to_datetime = str_to_datetime_processor_factory(
+ str_to_datetime = str_to_datetime_processor_factory( # noqa
DATETIME_RE, datetime.datetime
)
- str_to_time = str_to_datetime_processor_factory(TIME_RE, datetime.time)
- str_to_date = str_to_datetime_processor_factory(DATE_RE, datetime.date)
+ str_to_time = str_to_datetime_processor_factory( # noqa
+ TIME_RE, datetime.time
+ ) # noqa
+ str_to_date = str_to_datetime_processor_factory( # noqa
+ DATE_RE, datetime.date
+ ) # noqa
return locals()
try:
- from sqlalchemy.cprocessors import (
- UnicodeResultProcessor,
- DecimalResultProcessor,
- to_float,
- to_str,
- int_to_boolean,
- str_to_datetime,
- str_to_time,
- str_to_date,
- )
+ from sqlalchemy.cprocessors import DecimalResultProcessor # noqa
+ from sqlalchemy.cprocessors import int_to_boolean # noqa
+ from sqlalchemy.cprocessors import str_to_date # noqa
+ from sqlalchemy.cprocessors import str_to_datetime # noqa
+ from sqlalchemy.cprocessors import str_to_time # noqa
+ from sqlalchemy.cprocessors import to_float # noqa
+ from sqlalchemy.cprocessors import to_str # noqa
+ from sqlalchemy.cprocessors import UnicodeResultProcessor # noqa
def to_unicode_processor_factory(encoding, errors=None):
if errors is not None:
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index 598d499dc..199bb66dc 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -9,60 +9,50 @@
"""
-from .sql.base import SchemaVisitor
-
-
-from .sql.schema import (
- BLANK_SCHEMA,
- CheckConstraint,
- Column,
- ColumnDefault,
- Constraint,
- DefaultClause,
- DefaultGenerator,
- FetchedValue,
- ForeignKey,
- ForeignKeyConstraint,
- Index,
- MetaData,
- PassiveDefault,
- PrimaryKeyConstraint,
- SchemaItem,
- Sequence,
- Table,
- ThreadLocalMetaData,
- UniqueConstraint,
- _get_table_key,
- ColumnCollectionConstraint,
- ColumnCollectionMixin,
-)
-
-
-from .sql.naming import conv
-
-
-from .sql.ddl import (
- DDL,
- CreateTable,
- DropTable,
- CreateSequence,
- DropSequence,
- CreateIndex,
- DropIndex,
- CreateSchema,
- DropSchema,
- _DropView,
- CreateColumn,
- AddConstraint,
- DropConstraint,
- DDLBase,
- DDLElement,
- _CreateDropBase,
- _DDLCompiles,
- sort_tables,
- sort_tables_and_constraints,
- SetTableComment,
- DropTableComment,
- SetColumnComment,
- DropColumnComment,
-)
+from .sql.base import SchemaVisitor # noqa
+from .sql.ddl import _CreateDropBase # noqa
+from .sql.ddl import _DDLCompiles # noqa
+from .sql.ddl import _DropView # noqa
+from .sql.ddl import AddConstraint # noqa
+from .sql.ddl import CreateColumn # noqa
+from .sql.ddl import CreateIndex # noqa
+from .sql.ddl import CreateSchema # noqa
+from .sql.ddl import CreateSequence # noqa
+from .sql.ddl import CreateTable # noqa
+from .sql.ddl import DDL # noqa
+from .sql.ddl import DDLBase # noqa
+from .sql.ddl import DDLElement # noqa
+from .sql.ddl import DropColumnComment # noqa
+from .sql.ddl import DropConstraint # noqa
+from .sql.ddl import DropIndex # noqa
+from .sql.ddl import DropSchema # noqa
+from .sql.ddl import DropSequence # noqa
+from .sql.ddl import DropTable # noqa
+from .sql.ddl import DropTableComment # noqa
+from .sql.ddl import SetColumnComment # noqa
+from .sql.ddl import SetTableComment # noqa
+from .sql.ddl import sort_tables # noqa
+from .sql.ddl import sort_tables_and_constraints # noqa
+from .sql.naming import conv # noqa
+from .sql.schema import _get_table_key # noqa
+from .sql.schema import BLANK_SCHEMA # noqa
+from .sql.schema import CheckConstraint # noqa
+from .sql.schema import Column # noqa
+from .sql.schema import ColumnCollectionConstraint # noqa
+from .sql.schema import ColumnCollectionMixin # noqa
+from .sql.schema import ColumnDefault # noqa
+from .sql.schema import Constraint # noqa
+from .sql.schema import DefaultClause # noqa
+from .sql.schema import DefaultGenerator # noqa
+from .sql.schema import FetchedValue # noqa
+from .sql.schema import ForeignKey # noqa
+from .sql.schema import ForeignKeyConstraint # noqa
+from .sql.schema import Index # noqa
+from .sql.schema import MetaData # noqa
+from .sql.schema import PassiveDefault # noqa
+from .sql.schema import PrimaryKeyConstraint # noqa
+from .sql.schema import SchemaItem # noqa
+from .sql.schema import Sequence # noqa
+from .sql.schema import Table # noqa
+from .sql.schema import ThreadLocalMetaData # noqa
+from .sql.schema import UniqueConstraint # noqa
diff --git a/lib/sqlalchemy/sql/__init__.py b/lib/sqlalchemy/sql/__init__.py
index 87e2fb6c3..a46acc076 100644
--- a/lib/sqlalchemy/sql/__init__.py
+++ b/lib/sqlalchemy/sql/__init__.py
@@ -5,77 +5,74 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .expression import (
- Alias,
- ClauseElement,
- ColumnCollection,
- ColumnElement,
- CompoundSelect,
- Delete,
- FromClause,
- Insert,
- Join,
- Select,
- Selectable,
- TableClause,
- TableSample,
- Update,
- alias,
- and_,
- any_,
- all_,
- asc,
- between,
- bindparam,
- case,
- cast,
- collate,
- column,
- delete,
- desc,
- distinct,
- except_,
- except_all,
- exists,
- extract,
- false,
- False_,
- func,
- funcfilter,
- insert,
- intersect,
- intersect_all,
- join,
- label,
- lateral,
- literal,
- literal_column,
- modifier,
- not_,
- null,
- nullsfirst,
- nullslast,
- or_,
- outerjoin,
- outparam,
- over,
- quoted_name,
- select,
- subquery,
- table,
- tablesample,
- text,
- true,
- True_,
- tuple_,
- type_coerce,
- union,
- union_all,
- update,
- within_group,
-)
-
-from .visitors import ClauseVisitor
+from .expression import Alias # noqa
+from .expression import alias # noqa
+from .expression import all_ # noqa
+from .expression import and_ # noqa
+from .expression import any_ # noqa
+from .expression import asc # noqa
+from .expression import between # noqa
+from .expression import bindparam # noqa
+from .expression import case # noqa
+from .expression import cast # noqa
+from .expression import ClauseElement # noqa
+from .expression import collate # noqa
+from .expression import column # noqa
+from .expression import ColumnCollection # noqa
+from .expression import ColumnElement # noqa
+from .expression import CompoundSelect # noqa
+from .expression import Delete # noqa
+from .expression import delete # noqa
+from .expression import desc # noqa
+from .expression import distinct # noqa
+from .expression import except_ # noqa
+from .expression import except_all # noqa
+from .expression import exists # noqa
+from .expression import extract # noqa
+from .expression import false # noqa
+from .expression import False_ # noqa
+from .expression import FromClause # noqa
+from .expression import func # noqa
+from .expression import funcfilter # noqa
+from .expression import Insert # noqa
+from .expression import insert # noqa
+from .expression import intersect # noqa
+from .expression import intersect_all # noqa
+from .expression import Join # noqa
+from .expression import join # noqa
+from .expression import label # noqa
+from .expression import lateral # noqa
+from .expression import literal # noqa
+from .expression import literal_column # noqa
+from .expression import modifier # noqa
+from .expression import not_ # noqa
+from .expression import null # noqa
+from .expression import nullsfirst # noqa
+from .expression import nullslast # noqa
+from .expression import or_ # noqa
+from .expression import outerjoin # noqa
+from .expression import outparam # noqa
+from .expression import over # noqa
+from .expression import quoted_name # noqa
+from .expression import Select # noqa
+from .expression import select # noqa
+from .expression import Selectable # noqa
+from .expression import subquery # noqa
+from .expression import table # noqa
+from .expression import TableClause # noqa
+from .expression import TableSample # noqa
+from .expression import tablesample # noqa
+from .expression import text # noqa
+from .expression import true # noqa
+from .expression import True_ # noqa
+from .expression import tuple_ # noqa
+from .expression import type_coerce # noqa
+from .expression import union # noqa
+from .expression import union_all # noqa
+from .expression import Update # noqa
+from .expression import update # noqa
+from .expression import within_group # noqa
+from .visitors import ClauseVisitor # noqa
def __go(lcls):
@@ -90,9 +87,11 @@ def __go(lcls):
if not (name.startswith("_") or _inspect.ismodule(obj))
)
- from .annotation import _prepare_annotations, Annotated
- from .elements import AnnotatedColumnElement, ClauseList
- from .selectable import AnnotatedFromClause
+ from .annotation import _prepare_annotations
+ from .annotation import Annotated # noqa
+ from .elements import AnnotatedColumnElement
+ from .elements import ClauseList # noqa
+ from .selectable import AnnotatedFromClause # noqa
_prepare_annotations(ColumnElement, AnnotatedColumnElement)
_prepare_annotations(FromClause, AnnotatedFromClause)
@@ -100,7 +99,7 @@ def __go(lcls):
_sa_util.dependencies.resolve_all("sqlalchemy.sql")
- from . import naming
+ from . import naming # noqa
__go(locals())
diff --git a/lib/sqlalchemy/sql/annotation.py b/lib/sqlalchemy/sql/annotation.py
index 64cfa630e..0dc70a812 100644
--- a/lib/sqlalchemy/sql/annotation.py
+++ b/lib/sqlalchemy/sql/annotation.py
@@ -11,8 +11,8 @@ associations.
"""
-from .. import util
from . import operators
+from .. import util
class Annotated(object):
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py
index 45db215fe..1de7c5ea6 100644
--- a/lib/sqlalchemy/sql/base.py
+++ b/lib/sqlalchemy/sql/base.py
@@ -10,11 +10,14 @@
"""
-from .. import util, exc
import itertools
-from .visitors import ClauseVisitor
import re
+from .visitors import ClauseVisitor
+from .. import exc
+from .. import util
+
+
PARSE_AUTOCOMMIT = util.symbol("PARSE_AUTOCOMMIT")
NO_ARG = util.symbol("NO_ARG")
@@ -517,7 +520,7 @@ class ColumnCollection(util.OrderedProperties):
def __delitem__(self, key):
raise NotImplementedError()
- def __setattr__(self, key, object):
+ def __setattr__(self, key, obj):
raise NotImplementedError()
def __setitem__(self, key, value):
@@ -557,16 +560,16 @@ class ColumnCollection(util.OrderedProperties):
c for c in self._all_columns if c is not column
]
- def update(self, iter):
- cols = list(iter)
+ def update(self, iter_):
+ cols = list(iter_)
all_col_set = set(self._all_columns)
self._all_columns.extend(
c for label, c in cols if c not in all_col_set
)
self._data.update((label, c) for label, c in cols)
- def extend(self, iter):
- cols = list(iter)
+ def extend(self, iter_):
+ cols = list(iter_)
all_col_set = set(self._all_columns)
self._all_columns.extend(c for c in cols if c not in all_col_set)
self._data.update((c.key, c) for c in cols)
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index f641d0a84..c752da013 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -24,19 +24,20 @@ To generate user-defined SQL strings, see
"""
import contextlib
-import re
-from . import (
- schema,
- sqltypes,
- operators,
- functions,
- visitors,
- elements,
- selectable,
- crud,
-)
-from .. import util, exc
import itertools
+import re
+
+from . import crud
+from . import elements
+from . import functions
+from . import operators
+from . import schema
+from . import selectable
+from . import sqltypes
+from . import visitors
+from .. import exc
+from .. import util
+
RESERVED_WORDS = set(
[
@@ -2392,11 +2393,7 @@ class SQLCompiler(Compiled):
table_text = preparer.format_table(insert_stmt.table)
if insert_stmt._hints:
- dialect_hints, table_text = self._setup_crud_hints(
- insert_stmt, table_text
- )
- else:
- dialect_hints = None
+ _, table_text = self._setup_crud_hints(insert_stmt, table_text)
text += table_text
diff --git a/lib/sqlalchemy/sql/crud.py b/lib/sqlalchemy/sql/crud.py
index 602b91a25..6452badd2 100644
--- a/lib/sqlalchemy/sql/crud.py
+++ b/lib/sqlalchemy/sql/crud.py
@@ -9,11 +9,13 @@
within INSERT and UPDATE statements.
"""
-from .. import util
-from .. import exc
+import operator
+
from . import dml
from . import elements
-import operator
+from .. import exc
+from .. import util
+
REQUIRED = util.symbol(
"REQUIRED",
@@ -97,9 +99,11 @@ def _get_crud_params(compiler, stmt, **kw):
# getters - these are normally just column.key,
# but in the case of mysql multi-table update, the rules for
# .key must conditionally take tablename into account
- _column_as_key, _getattr_col_key, _col_bind_name = _key_getters_for_crud_column(
- compiler, stmt
- )
+ (
+ _column_as_key,
+ _getattr_col_key,
+ _col_bind_name,
+ ) = _key_getters_for_crud_column(compiler, stmt)
# if we have statement parameters - set defaults in the
# compiled params
@@ -241,9 +245,12 @@ def _scan_insert_from_select_cols(
kw,
):
- need_pks, implicit_returning, implicit_return_defaults, postfetch_lastrowid = _get_returning_modifiers(
- compiler, stmt
- )
+ (
+ need_pks,
+ implicit_returning,
+ implicit_return_defaults,
+ postfetch_lastrowid,
+ ) = _get_returning_modifiers(compiler, stmt)
cols = [stmt.table.c[_column_as_key(name)] for name in stmt.select_names]
@@ -286,9 +293,12 @@ def _scan_cols(
kw,
):
- need_pks, implicit_returning, implicit_return_defaults, postfetch_lastrowid = _get_returning_modifiers(
- compiler, stmt
- )
+ (
+ need_pks,
+ implicit_returning,
+ implicit_return_defaults,
+ postfetch_lastrowid,
+ ) = _get_returning_modifiers(compiler, stmt)
if stmt._parameter_ordering:
parameter_ordering = [
diff --git a/lib/sqlalchemy/sql/ddl.py b/lib/sqlalchemy/sql/ddl.py
index f21b3d7f0..f247fa782 100644
--- a/lib/sqlalchemy/sql/ddl.py
+++ b/lib/sqlalchemy/sql/ddl.py
@@ -10,12 +10,15 @@ to invoke them for a create/drop call.
"""
-from .. import util
+from .base import _bind_or_error
+from .base import _generative
+from .base import Executable
+from .base import SchemaVisitor
from .elements import ClauseElement
-from .base import Executable, _generative, SchemaVisitor, _bind_or_error
-from ..util import topological
from .. import event
from .. import exc
+from .. import util
+from ..util import topological
class _DDLCompiles(ClauseElement):
@@ -168,7 +171,7 @@ class DDLElement(Executable, _DDLCompiles):
DDL('something').execute_if(dialect=('postgresql', 'mysql'))
- :param callable_: A callable, which will be invoked with
+ :param callable\_: A callable, which will be invoked with
four positional arguments as well as optional keyword
arguments:
@@ -815,10 +818,13 @@ class SchemaGenerator(DDLBase):
include_foreign_key_constraints = None
self.connection.execute(
+ # fmt: off
CreateTable(
table,
- include_foreign_key_constraints=include_foreign_key_constraints,
+ include_foreign_key_constraints= # noqa
+ include_foreign_key_constraints,
)
+ # fmt: on
)
if hasattr(table, "indexes"):
diff --git a/lib/sqlalchemy/sql/default_comparator.py b/lib/sqlalchemy/sql/default_comparator.py
index fa0052198..69196341f 100644
--- a/lib/sqlalchemy/sql/default_comparator.py
+++ b/lib/sqlalchemy/sql/default_comparator.py
@@ -8,34 +8,34 @@
"""Default implementation of SQL comparison operations.
"""
-from .. import exc, util
-from . import type_api
from . import operators
-from .elements import (
- BindParameter,
- True_,
- False_,
- BinaryExpression,
- Null,
- _const_expr,
- _clause_element_as_expr,
- ClauseList,
- ColumnElement,
- TextClause,
- UnaryExpression,
- collate,
- _is_literal,
- _literal_as_text,
- ClauseElement,
- and_,
- or_,
- Slice,
- Visitable,
- _literal_as_binds,
- CollectionAggregate,
- Tuple,
-)
-from .selectable import SelectBase, Alias, Selectable, ScalarSelect
+from . import type_api
+from .elements import _clause_element_as_expr
+from .elements import _const_expr
+from .elements import _is_literal
+from .elements import _literal_as_text
+from .elements import and_
+from .elements import BinaryExpression
+from .elements import BindParameter
+from .elements import ClauseElement
+from .elements import ClauseList
+from .elements import collate
+from .elements import CollectionAggregate
+from .elements import ColumnElement
+from .elements import False_
+from .elements import Null
+from .elements import or_
+from .elements import TextClause
+from .elements import True_
+from .elements import Tuple
+from .elements import UnaryExpression
+from .elements import Visitable
+from .selectable import Alias
+from .selectable import ScalarSelect
+from .selectable import Selectable
+from .selectable import SelectBase
+from .. import exc
+from .. import util
def _boolean_compare(
diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py
index 0cea5ccc4..39a3b39d3 100644
--- a/lib/sqlalchemy/sql/dml.py
+++ b/lib/sqlalchemy/sql/dml.py
@@ -9,29 +9,22 @@ Provide :class:`.Insert`, :class:`.Update` and :class:`.Delete`.
"""
-from .base import (
- Executable,
- _generative,
- _from_objects,
- DialectKWArgs,
- ColumnCollection,
-)
-from .elements import (
- ClauseElement,
- _literal_as_text,
- Null,
- and_,
- _clone,
- _column_as_key,
-)
-from .selectable import (
- _interpret_as_from,
- _interpret_as_select,
- HasPrefixes,
- HasCTE,
-)
-from .. import util
+from .base import _from_objects
+from .base import _generative
+from .base import DialectKWArgs
+from .base import Executable
+from .elements import _clone
+from .elements import _column_as_key
+from .elements import _literal_as_text
+from .elements import and_
+from .elements import ClauseElement
+from .elements import Null
+from .selectable import _interpret_as_from
+from .selectable import _interpret_as_select
+from .selectable import HasCTE
+from .selectable import HasPrefixes
from .. import exc
+from .. import util
class UpdateBase(
@@ -372,9 +365,10 @@ class ValuesBase(UpdateBase):
v = {}
if self.parameters is None:
- self.parameters, self._has_multi_parameters = self._process_colparams(
- v
- )
+ (
+ self.parameters,
+ self._has_multi_parameters,
+ ) = self._process_colparams(v)
else:
if self._has_multi_parameters:
self.parameters = list(self.parameters)
@@ -714,17 +708,17 @@ class Update(ValuesBase):
:meth:`.ResultProxy.last_updated_params`.
:param preserve_parameter_order: if True, the update statement is
- expected to receive parameters **only** via the :meth:`.Update.values`
- method, and they must be passed as a Python ``list`` of 2-tuples.
- The rendered UPDATE statement will emit the SET clause for each
- referenced column maintaining this order.
+ expected to receive parameters **only** via the
+ :meth:`.Update.values` method, and they must be passed as a Python
+ ``list`` of 2-tuples. The rendered UPDATE statement will emit the SET
+ clause for each referenced column maintaining this order.
.. versionadded:: 1.0.10
.. seealso::
:ref:`updates_order_parameters` - full example of the
- :paramref:`~sqlalchemy.sql.expression.update.preserve_parameter_order` flag
+ :paramref:`~.update.preserve_parameter_order` flag
If both ``values`` and compile-time bind parameters are present, the
compile-time bind parameters override the information specified
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index e857f2da8..858695719 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -12,18 +12,25 @@
from __future__ import unicode_literals
-from .. import util, exc, inspection
-from . import type_api
-from . import operators
-from .visitors import Visitable, cloned_traverse, traverse
-from .annotation import Annotated
import itertools
-from .base import Executable, PARSE_AUTOCOMMIT, Immutable, NO_ARG
-from .base import _generative
import numbers
-
-import re
import operator
+import re
+
+from . import operators
+from . import type_api
+from .annotation import Annotated
+from .base import _generative
+from .base import Executable
+from .base import Immutable
+from .base import NO_ARG
+from .base import PARSE_AUTOCOMMIT
+from .visitors import cloned_traverse
+from .visitors import traverse
+from .visitors import Visitable
+from .. import exc
+from .. import inspection
+from .. import util
def _clone(element, **kw):
@@ -450,7 +457,9 @@ class ClauseElement(Visitable):
if util.py3k:
return str(self.compile())
else:
- return unicode(self.compile()).encode("ascii", "backslashreplace")
+ return unicode(self.compile()).encode( # noqa
+ "ascii", "backslashreplace"
+ ) # noqa
def __and__(self, other):
"""'and' at the ClauseElement level.
@@ -1244,8 +1253,8 @@ class TypeClause(ClauseElement):
__visit_name__ = "typeclause"
- def __init__(self, type):
- self.type = type
+ def __init__(self, type_):
+ self.type = type_
class TextClause(Executable, ClauseElement):
@@ -1609,10 +1618,10 @@ class TextClause(Executable, ClauseElement):
for id, name, timestamp in connection.execute(stmt):
print(id, name, timestamp)
- The positional form of :meth:`.TextClause.columns` also provides
- the unique feature of **positional column targeting**, which is
- particularly useful when using the ORM with complex textual queries.
- If we specify the columns from our model to :meth:`.TextClause.columns`,
+ The positional form of :meth:`.TextClause.columns` also provides the
+ unique feature of **positional column targeting**, which is
+ particularly useful when using the ORM with complex textual queries. If
+ we specify the columns from our model to :meth:`.TextClause.columns`,
the result set will match to those columns positionally, meaning the
name or origin of the column in the textual SQL doesn't matter::
@@ -2382,7 +2391,7 @@ class Cast(ColumnElement):
__visit_name__ = "cast"
def __init__(self, expression, type_):
- """Produce a ``CAST`` expression.
+ r"""Produce a ``CAST`` expression.
:func:`.cast` returns an instance of :class:`.Cast`.
@@ -2421,7 +2430,7 @@ class Cast(ColumnElement):
expression or a Python string which will be coerced into a bound
literal value.
- :param type_: A :class:`.TypeEngine` class or instance indicating
+ :param type\_: A :class:`.TypeEngine` class or instance indicating
the type to which the ``CAST`` should apply.
.. seealso::
@@ -2465,7 +2474,7 @@ class TypeCoerce(ColumnElement):
__visit_name__ = "type_coerce"
def __init__(self, expression, type_):
- """Associate a SQL expression with a particular type, without rendering
+ r"""Associate a SQL expression with a particular type, without rendering
``CAST``.
E.g.::
@@ -2517,7 +2526,7 @@ class TypeCoerce(ColumnElement):
expression or a Python string which will be coerced into a bound
literal value.
- :param type_: A :class:`.TypeEngine` class or instance indicating
+ :param type\_: A :class:`.TypeEngine` class or instance indicating
the type to which the expression is coerced.
.. seealso::
@@ -3234,7 +3243,7 @@ class Over(ColumnElement):
def __init__(
self, element, partition_by=None, order_by=None, range_=None, rows=None
):
- """Produce an :class:`.Over` object against a function.
+ r"""Produce an :class:`.Over` object against a function.
Used against aggregate or so-called "window" functions,
for database backends that support window functions.
@@ -3253,11 +3262,13 @@ class Over(ColumnElement):
mutually-exclusive parameters each accept a 2-tuple, which contains
a combination of integers and None::
- func.row_number().over(order_by=my_table.c.some_column, range_=(None, 0))
+ func.row_number().over(
+ order_by=my_table.c.some_column, range_=(None, 0))
The above would produce::
- ROW_NUMBER() OVER(ORDER BY some_column RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
+ ROW_NUMBER() OVER(ORDER BY some_column
+ RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
A value of None indicates "unbounded", a
value of zero indicates "current row", and negative / positive
@@ -3290,7 +3301,7 @@ class Over(ColumnElement):
:param order_by: a column element or string, or a list
of such, that will be used as the ORDER BY clause
of the OVER construct.
- :param range_: optional range clause for the window. This is a
+ :param range\_: optional range clause for the window. This is a
tuple value which can contain integer values or None, and will
render a RANGE BETWEEN PRECEDING / FOLLOWING clause
diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py
index aab9f46d4..d8e5f170a 100644
--- a/lib/sqlalchemy/sql/expression.py
+++ b/lib/sqlalchemy/sql/expression.py
@@ -81,80 +81,98 @@ __all__ = [
]
-from .visitors import Visitable
-from .functions import func, modifier, FunctionElement, Function
-from ..util.langhelpers import public_factory
-from .elements import (
- ClauseElement,
- ColumnElement,
- BindParameter,
- CollectionAggregate,
- UnaryExpression,
- BooleanClauseList,
- Label,
- Cast,
- Case,
- ColumnClause,
- TextClause,
- Over,
- Null,
- True_,
- False_,
- BinaryExpression,
- Tuple,
- TypeClause,
- Extract,
- Grouping,
- WithinGroup,
- not_,
- quoted_name,
- collate,
- literal_column,
- between,
- literal,
- outparam,
- TypeCoerce,
- ClauseList,
- FunctionFilter,
-)
-
-from .elements import (
- SavepointClause,
- RollbackToSavepointClause,
- ReleaseSavepointClause,
-)
-
-from .base import ColumnCollection, Generative, Executable, PARSE_AUTOCOMMIT
-
-from .selectable import (
- Alias,
- Join,
- Select,
- Selectable,
- TableClause,
- CompoundSelect,
- CTE,
- FromClause,
- FromGrouping,
- Lateral,
- SelectBase,
- alias,
- GenerativeSelect,
- subquery,
- HasCTE,
- HasPrefixes,
- HasSuffixes,
- lateral,
- Exists,
- ScalarSelect,
- TextAsFrom,
- TableSample,
- tablesample,
-)
+from .base import _from_objects # noqa
+from .base import ColumnCollection # noqa
+from .base import Executable # noqa
+from .base import Generative # noqa
+from .base import PARSE_AUTOCOMMIT # noqa
+from .dml import Delete # noqa
+from .dml import Insert # noqa
+from .dml import Update # noqa
+from .dml import UpdateBase # noqa
+from .dml import ValuesBase # noqa
+from .elements import _clause_element_as_expr # noqa
+from .elements import _clone # noqa
+from .elements import _cloned_difference # noqa
+from .elements import _cloned_intersection # noqa
+from .elements import _column_as_key # noqa
+from .elements import _corresponding_column_or_error # noqa
+from .elements import _expression_literal_as_text # noqa
+from .elements import _is_column # noqa
+from .elements import _labeled # noqa
+from .elements import _literal_as_binds # noqa
+from .elements import _literal_as_label_reference # noqa
+from .elements import _literal_as_text # noqa
+from .elements import _only_column_elements # noqa
+from .elements import _select_iterables # noqa
+from .elements import _string_or_unprintable # noqa
+from .elements import _truncated_label # noqa
+from .elements import between # noqa
+from .elements import BinaryExpression # noqa
+from .elements import BindParameter # noqa
+from .elements import BooleanClauseList # noqa
+from .elements import Case # noqa
+from .elements import Cast # noqa
+from .elements import ClauseElement # noqa
+from .elements import ClauseList # noqa
+from .elements import collate # noqa
+from .elements import CollectionAggregate # noqa
+from .elements import ColumnClause # noqa
+from .elements import ColumnElement # noqa
+from .elements import Extract # noqa
+from .elements import False_ # noqa
+from .elements import FunctionFilter # noqa
+from .elements import Grouping # noqa
+from .elements import Label # noqa
+from .elements import literal # noqa
+from .elements import literal_column # noqa
+from .elements import not_ # noqa
+from .elements import Null # noqa
+from .elements import outparam # noqa
+from .elements import Over # noqa
+from .elements import quoted_name # noqa
+from .elements import ReleaseSavepointClause # noqa
+from .elements import RollbackToSavepointClause # noqa
+from .elements import SavepointClause # noqa
+from .elements import TextClause # noqa
+from .elements import True_ # noqa
+from .elements import Tuple # noqa
+from .elements import TypeClause # noqa
+from .elements import TypeCoerce # noqa
+from .elements import UnaryExpression # noqa
+from .elements import WithinGroup # noqa
+from .functions import func # noqa
+from .functions import Function # noqa
+from .functions import FunctionElement # noqa
+from .functions import modifier # noqa
+from .selectable import _interpret_as_from # noqa
+from .selectable import Alias # noqa
+from .selectable import alias # noqa
+from .selectable import CompoundSelect # noqa
+from .selectable import CTE # noqa
+from .selectable import Exists # noqa
+from .selectable import FromClause # noqa
+from .selectable import FromGrouping # noqa
+from .selectable import GenerativeSelect # noqa
+from .selectable import HasCTE # noqa
+from .selectable import HasPrefixes # noqa
+from .selectable import HasSuffixes # noqa
+from .selectable import Join # noqa
+from .selectable import Lateral # noqa
+from .selectable import lateral # noqa
+from .selectable import ScalarSelect # noqa
+from .selectable import Select # noqa
+from .selectable import Selectable # noqa
+from .selectable import SelectBase # noqa
+from .selectable import subquery # noqa
+from .selectable import TableClause # noqa
+from .selectable import TableSample # noqa
+from .selectable import tablesample # noqa
+from .selectable import TextAsFrom # noqa
+from .visitors import Visitable # noqa
+from ..util.langhelpers import public_factory # noqa
-from .dml import Insert, Update, Delete, UpdateBase, ValuesBase
-
# factory functions - these pull class-bound constructors and classmethods
# from SQL elements and selectables into public functions. This allows
# the functions to be available in the sqlalchemy.sql.* namespace and
@@ -174,7 +192,7 @@ within_group = public_factory(WithinGroup, ".expression.within_group")
label = public_factory(Label, ".expression.label")
case = public_factory(Case, ".expression.case")
cast = public_factory(Cast, ".expression.cast")
-extract = public_factory(Extract, ".expression.extract")
+extract = public_factory(Extract, ".exp # noqaression.extract")
tuple_ = public_factory(Tuple, ".expression.tuple_")
except_ = public_factory(CompoundSelect._create_except, ".expression.except_")
except_all = public_factory(
@@ -216,26 +234,6 @@ funcfilter = public_factory(FunctionFilter, ".expression.funcfilter")
# internal functions still being called from tests and the ORM,
# these might be better off in some other namespace
-from .base import _from_objects
-from .elements import (
- _literal_as_text,
- _clause_element_as_expr,
- _is_column,
- _labeled,
- _only_column_elements,
- _string_or_unprintable,
- _truncated_label,
- _clone,
- _cloned_difference,
- _cloned_intersection,
- _column_as_key,
- _literal_as_binds,
- _select_iterables,
- _corresponding_column_or_error,
- _literal_as_label_reference,
- _expression_literal_as_text,
-)
-from .selectable import _interpret_as_from
# old names for compatibility
diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py
index 883bb8cc3..e191cff15 100644
--- a/lib/sqlalchemy/sql/functions.py
+++ b/lib/sqlalchemy/sql/functions.py
@@ -8,30 +8,33 @@
"""SQL function API, factories, and built-in functions.
"""
-from . import sqltypes, schema
-from .base import Executable, ColumnCollection
-from .elements import (
- ClauseList,
- Cast,
- Extract,
- _literal_as_binds,
- literal_column,
- _type_from_args,
- ColumnElement,
- _clone,
- Over,
- BindParameter,
- FunctionFilter,
- Grouping,
- WithinGroup,
- BinaryExpression,
-)
-from .selectable import FromClause, Select, Alias
-from . import util as sqlutil
+from . import annotation
from . import operators
+from . import schema
+from . import sqltypes
+from . import util as sqlutil
+from .base import ColumnCollection
+from .base import Executable
+from .elements import _clone
+from .elements import _literal_as_binds
+from .elements import _type_from_args
+from .elements import BinaryExpression
+from .elements import BindParameter
+from .elements import Cast
+from .elements import ClauseList
+from .elements import ColumnElement
+from .elements import Extract
+from .elements import FunctionFilter
+from .elements import Grouping
+from .elements import literal_column
+from .elements import Over
+from .elements import WithinGroup
+from .selectable import Alias
+from .selectable import FromClause
+from .selectable import Select
from .visitors import VisitableType
from .. import util
-from . import annotation
+
_registry = util.defaultdict(dict)
@@ -718,19 +721,19 @@ class coalesce(ReturnTypeFromArgs):
_has_args = True
-class max(ReturnTypeFromArgs):
+class max(ReturnTypeFromArgs): # noqa
pass
-class min(ReturnTypeFromArgs):
+class min(ReturnTypeFromArgs): # noqa
pass
-class sum(ReturnTypeFromArgs):
+class sum(ReturnTypeFromArgs): # noqa
pass
-class now(GenericFunction):
+class now(GenericFunction): # noqa
type = sqltypes.DateTime
@@ -813,7 +816,8 @@ class array_agg(GenericFunction):
.. seealso::
:func:`.postgresql.array_agg` - PostgreSQL-specific version that
- returns :class:`.postgresql.ARRAY`, which has PG-specific operators added.
+ returns :class:`.postgresql.ARRAY`, which has PG-specific operators
+ added.
"""
diff --git a/lib/sqlalchemy/sql/naming.py b/lib/sqlalchemy/sql/naming.py
index 144cc4dfc..ec6bc6a3b 100644
--- a/lib/sqlalchemy/sql/naming.py
+++ b/lib/sqlalchemy/sql/naming.py
@@ -10,21 +10,23 @@
"""
-from .schema import (
- Constraint,
- ForeignKeyConstraint,
- PrimaryKeyConstraint,
- UniqueConstraint,
- CheckConstraint,
- Index,
- Table,
- Column,
-)
-from .. import event, events
-from .. import exc
-from .elements import _truncated_label, _defer_name, _defer_none_name, conv
import re
+from .elements import _defer_name
+from .elements import _defer_none_name
+from .elements import conv
+from .schema import CheckConstraint
+from .schema import Column
+from .schema import Constraint
+from .schema import ForeignKeyConstraint
+from .schema import Index
+from .schema import PrimaryKeyConstraint
+from .schema import Table
+from .schema import UniqueConstraint
+from .. import event
+from .. import events # noqa
+from .. import exc
+
class ConventionDict(object):
def __init__(self, const, table, convention):
diff --git a/lib/sqlalchemy/sql/operators.py b/lib/sqlalchemy/sql/operators.py
index 2b843d751..379e7337f 100644
--- a/lib/sqlalchemy/sql/operators.py
+++ b/lib/sqlalchemy/sql/operators.py
@@ -10,29 +10,28 @@
"""Defines operators used in SQL expressions."""
+from operator import add
+from operator import and_
+from operator import contains
+from operator import eq
+from operator import ge
+from operator import getitem
+from operator import gt
+from operator import inv
+from operator import le
+from operator import lshift
+from operator import lt
+from operator import mod
+from operator import mul
+from operator import ne
+from operator import neg
+from operator import or_
+from operator import rshift
+from operator import sub
+from operator import truediv
+
from .. import util
-from operator import (
- and_,
- or_,
- inv,
- add,
- mul,
- sub,
- mod,
- truediv,
- lt,
- le,
- ne,
- gt,
- ge,
- eq,
- neg,
- getitem,
- lshift,
- rshift,
- contains,
-)
if util.py2k:
from operator import div
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index d6c3f5000..804c8bdb8 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -30,25 +30,30 @@ as components in SQL expressions.
"""
from __future__ import absolute_import
-from .. import exc, util, event, inspection
-from .base import SchemaEventTarget, DialectKWArgs
-import operator
-from . import visitors
-from . import type_api
-from .base import _bind_or_error, ColumnCollection
-from .elements import (
- ClauseElement,
- ColumnClause,
- _as_truncated,
- TextClause,
- _literal_as_text,
- ColumnElement,
- quoted_name,
-)
-from .selectable import TableClause
import collections
+import operator
+
import sqlalchemy
from . import ddl
+from . import type_api
+from . import visitors
+from .base import _bind_or_error
+from .base import ColumnCollection
+from .base import DialectKWArgs
+from .base import SchemaEventTarget
+from .elements import _as_truncated
+from .elements import _literal_as_text
+from .elements import ClauseElement
+from .elements import ColumnClause
+from .elements import ColumnElement
+from .elements import quoted_name
+from .elements import TextClause
+from .selectable import TableClause
+from .. import event
+from .. import exc
+from .. import inspection
+from .. import util
+
RETAIN_SCHEMA = util.symbol("retain_schema")
@@ -373,11 +378,11 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
the table resides in a schema other than the default selected schema
for the engine's database connection. Defaults to ``None``.
- If the owning :class:`.MetaData` of this :class:`.Table` specifies
- its own :paramref:`.MetaData.schema` parameter, then that schema
- name will be applied to this :class:`.Table` if the schema parameter
- here is set to ``None``. To set a blank schema name on a :class:`.Table`
- that would otherwise use the schema set on the owning :class:`.MetaData`,
+ If the owning :class:`.MetaData` of this :class:`.Table` specifies its
+ own :paramref:`.MetaData.schema` parameter, then that schema name will
+ be applied to this :class:`.Table` if the schema parameter here is set
+ to ``None``. To set a blank schema name on a :class:`.Table` that
+ would otherwise use the schema set on the owning :class:`.MetaData`,
specify the special symbol :attr:`.BLANK_SCHEMA`.
.. versionadded:: 1.0.14 Added the :attr:`.BLANK_SCHEMA` symbol to
@@ -386,10 +391,9 @@ class Table(DialectKWArgs, SchemaItem, TableClause):
The quoting rules for the schema name are the same as those for the
``name`` parameter, in that quoting is applied for reserved words or
- case-sensitive names; to enable unconditional quoting for the
- schema name, specify the flag
- ``quote_schema=True`` to the constructor, or use the
- :class:`.quoted_name` construct to specify the name.
+ case-sensitive names; to enable unconditional quoting for the schema
+ name, specify the flag ``quote_schema=True`` to the constructor, or use
+ the :class:`.quoted_name` construct to specify the name.
:param useexisting: Deprecated. Use :paramref:`.Table.extend_existing`.
@@ -1070,9 +1074,9 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause):
Column('id', ForeignKey('other.id'),
primary_key=True, autoincrement='ignore_fk')
- It is typically not desirable to have "autoincrement" enabled
- on a column that refers to another via foreign key, as such a column
- is required to refer to a value that originates from elsewhere.
+ It is typically not desirable to have "autoincrement" enabled on a
+ column that refers to another via foreign key, as such a column is
+ required to refer to a value that originates from elsewhere.
The setting has these two effects on columns that meet the
above criteria:
@@ -4021,8 +4025,8 @@ class MetaData(SchemaItem):
To resolve these cycles, either the
:paramref:`.ForeignKeyConstraint.use_alter` parameter may be appled
to those constraints, or use the
- :func:`.schema.sort_tables_and_constraints` function which will break
- out foreign key constraints involved in cycles separately.
+ :func:`.schema.sort_tables_and_constraints` function which will
+ break out foreign key constraints involved in cycles separately.
.. seealso::
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index 1f1800514..beba1d242 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -10,50 +10,45 @@ SQL tables and derived rowsets.
"""
-from .elements import (
- ClauseElement,
- TextClause,
- ClauseList,
- and_,
- Grouping,
- UnaryExpression,
- literal_column,
- BindParameter,
-)
-from .elements import (
- _clone,
- _literal_as_text,
- _interpret_as_column_or_from,
- _expand_cloned,
- _select_iterables,
- _anonymous_label,
- _clause_element_as_expr,
- _cloned_intersection,
- _cloned_difference,
- True_,
- _literal_as_label_reference,
- _literal_and_labels_as_label_reference,
-)
-from .base import (
- Immutable,
- Executable,
- _generative,
- ColumnCollection,
- ColumnSet,
- _from_objects,
- Generative,
-)
-from . import type_api
-from .. import inspection
-from .. import util
-from .. import exc
-from operator import attrgetter
-from . import operators
-import operator
import collections
-from .annotation import Annotated
import itertools
+import operator
+from operator import attrgetter
+
from sqlalchemy.sql.visitors import Visitable
+from . import operators
+from . import type_api
+from .annotation import Annotated
+from .base import _from_objects
+from .base import _generative
+from .base import ColumnCollection
+from .base import ColumnSet
+from .base import Executable
+from .base import Generative
+from .base import Immutable
+from .elements import _anonymous_label
+from .elements import _clause_element_as_expr
+from .elements import _clone
+from .elements import _cloned_difference
+from .elements import _cloned_intersection
+from .elements import _expand_cloned
+from .elements import _interpret_as_column_or_from
+from .elements import _literal_and_labels_as_label_reference
+from .elements import _literal_as_label_reference
+from .elements import _literal_as_text
+from .elements import _select_iterables
+from .elements import and_
+from .elements import BindParameter
+from .elements import ClauseElement
+from .elements import ClauseList
+from .elements import Grouping
+from .elements import literal_column
+from .elements import TextClause
+from .elements import True_
+from .elements import UnaryExpression
+from .. import exc
+from .. import inspection
+from .. import util
def _interpret_as_from(element):
@@ -1013,15 +1008,15 @@ class Join(FromClause):
to join, or no way to join, an error is raised.
:param ignore_nonexistent_tables: Deprecated - this
- flag is no longer used. Only resolution errors regarding
- the two given tables are propagated.
+ flag is no longer used. Only resolution errors regarding
+ the two given tables are propagated.
:param a_subset: An optional expression that is a sub-component
- of ``a``. An attempt will be made to join to just this sub-component
- first before looking at the full ``a`` construct, and if found
- will be successful even if there are other ways to join to ``a``.
- This allows the "right side" of a join to be passed thereby
- providing a "natural join".
+ of ``a``. An attempt will be made to join to just this sub-component
+ first before looking at the full ``a`` construct, and if found
+ will be successful even if there are other ways to join to ``a``.
+ This allows the "right side" of a join to be passed thereby
+ providing a "natural join".
"""
constraints = cls._joincond_scan_left_right(
@@ -1441,8 +1436,8 @@ class TableSample(Alias):
"""Represent a TABLESAMPLE clause.
This object is constructed from the :func:`~.expression.tablesample` module
- level function as well as the :meth:`.FromClause.tablesample` method available
- on all :class:`.FromClause` subclasses.
+ level function as well as the :meth:`.FromClause.tablesample` method
+ available on all :class:`.FromClause` subclasses.
.. versionadded:: 1.1
@@ -2813,8 +2808,8 @@ class Select(HasPrefixes, HasSuffixes, GenerativeSelect):
a numerical value which usually renders as a ``LIMIT``
expression in the resulting select. Backends that don't
support ``LIMIT`` will attempt to provide similar
- functionality. This parameter is typically specified more naturally
- using the :meth:`.Select.limit` method on an existing
+ functionality. This parameter is typically specified more
+ naturally using the :meth:`.Select.limit` method on an existing
:class:`.Select`.
.. seealso::
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py
index 61fc6d3c9..65527645b 100644
--- a/lib/sqlalchemy/sql/sqltypes.py
+++ b/lib/sqlalchemy/sql/sqltypes.py
@@ -9,35 +9,35 @@
"""
-import datetime as dt
import codecs
-import collections
+import datetime as dt
+import decimal
import json
from . import elements
-from .type_api import (
- TypeEngine,
- TypeDecorator,
- to_instance,
- Variant,
- Emulated,
- NativeForEmulated,
-)
-from .elements import (
- quoted_name,
- TypeCoerce as type_coerce,
- _defer_name,
- Slice,
- _literal_as_binds,
-)
-from .. import exc, util, processors
-from .base import _bind_or_error, SchemaEventTarget
from . import operators
-from .. import inspection
+from . import type_api
+from .base import _bind_or_error
+from .base import SchemaEventTarget
+from .elements import _defer_name
+from .elements import _literal_as_binds
+from .elements import quoted_name
+from .elements import Slice
+from .elements import TypeCoerce as type_coerce # noqa
+from .type_api import Emulated
+from .type_api import NativeForEmulated # noqa
+from .type_api import to_instance
+from .type_api import TypeDecorator
+from .type_api import TypeEngine
+from .type_api import Variant
from .. import event
-from ..util import pickle
+from .. import exc
+from .. import inspection
+from .. import processors
+from .. import util
from ..util import compat
-import decimal
+from ..util import pickle
+
if util.jython:
import array
@@ -109,9 +109,11 @@ class Indexable(object):
raise NotImplementedError()
def __getitem__(self, index):
- adjusted_op, adjusted_right_expr, result_type = self._setup_getitem(
- index
- )
+ (
+ adjusted_op,
+ adjusted_right_expr,
+ result_type,
+ ) = self._setup_getitem(index)
return self.operate(
adjusted_op, adjusted_right_expr, result_type=result_type
)
@@ -1661,8 +1663,8 @@ class Boolean(Emulated, TypeEngine, SchemaType):
"""A bool datatype.
- :class:`.Boolean` typically uses BOOLEAN or SMALLINT on the DDL side, and on
- the Python side deals in ``True`` or ``False``.
+ :class:`.Boolean` typically uses BOOLEAN or SMALLINT on the DDL side,
+ and on the Python side deals in ``True`` or ``False``.
The :class:`.Boolean` datatype currently has two levels of assertion
that the values persisted are simple true/false values. For all
@@ -1938,16 +1940,17 @@ class JSON(Indexable, TypeEngine):
just the basic type.
Index operations return an expression object whose type defaults to
- :class:`.JSON` by default, so that further JSON-oriented instructions
- may be called upon the result type. Note that there are backend-specific
- idiosyncracies here, including that the PostgreSQL database does not generally
- compare a "json" to a "json" structure without type casts. These idiosyncracies
- can be accommodated in a backend-neutral way by making explicit use
- of the :func:`.cast` and :func:`.type_coerce` constructs.
- Comparison of specific index elements of a :class:`.JSON` object
- to other objects works best if the **left hand side is CAST to a string**
- and the **right hand side is rendered as a JSON string**; a future SQLAlchemy
- feature such as a generic "astext" modifier may simplify this at some point:
+ :class:`.JSON` by default, so that further JSON-oriented instructions may
+ be called upon the result type. Note that there are backend-specific
+ idiosyncracies here, including that the PostgreSQL database does not
+ generally compare a "json" to a "json" structure without type casts. These
+ idiosyncracies can be accommodated in a backend-neutral way by making
+ explicit use of the :func:`.cast` and :func:`.type_coerce` constructs.
+ Comparison of specific index elements of a :class:`.JSON` object to other
+ objects works best if the **left hand side is CAST to a string** and the
+ **right hand side is rendered as a JSON string**; a future SQLAlchemy
+ feature such as a generic "astext" modifier may simplify this at some
+ point:
* **Compare an element of a JSON structure to a string**::
@@ -1973,9 +1976,9 @@ class JSON(Indexable, TypeEngine):
data_table.c.data['some_key'], String
) == type_coerce(55, JSON)
- * **Compare an element of a JSON structure to some other JSON structure** - note
- that Python dictionaries are typically not ordered so care should be taken
- here to assert that the JSON structures are identical::
+ * **Compare an element of a JSON structure to some other JSON structure**
+ - note that Python dictionaries are typically not ordered so care should
+ be taken here to assert that the JSON structures are identical::
from sqlalchemy import cast, type_coerce
from sqlalchemy import String, JSON
@@ -2050,8 +2053,11 @@ class JSON(Indexable, TypeEngine):
from sqlalchemy import null
from sqlalchemy.dialects.postgresql import JSON
- obj1 = MyObject(json_value=null()) # will *always* insert SQL NULL
- obj2 = MyObject(json_value=JSON.NULL) # will *always* insert JSON string "null"
+ # will *always* insert SQL NULL
+ obj1 = MyObject(json_value=null())
+
+ # will *always* insert JSON string "null"
+ obj2 = MyObject(json_value=JSON.NULL)
session.add_all([obj1, obj2])
session.commit()
@@ -2089,8 +2095,8 @@ class JSON(Indexable, TypeEngine):
:paramref:`.JSON.none_as_null` does **not** apply to the
values passed to :paramref:`.Column.default` and
- :paramref:`.Column.server_default`; a value of ``None`` passed for
- these parameters means "no default present".
+ :paramref:`.Column.server_default`; a value of ``None``
+ passed for these parameters means "no default present".
.. seealso::
@@ -2238,11 +2244,11 @@ class ARRAY(SchemaEventTarget, Indexable, Concatenable, TypeEngine):
with PostgreSQL, as it provides additional operators specific
to that backend.
- :class:`.types.ARRAY` is part of the Core in support of various SQL standard
- functions such as :class:`.array_agg` which explicitly involve arrays;
- however, with the exception of the PostgreSQL backend and possibly
- some third-party dialects, no other SQLAlchemy built-in dialect has
- support for this type.
+ :class:`.types.ARRAY` is part of the Core in support of various SQL
+ standard functions such as :class:`.array_agg` which explicitly involve
+ arrays; however, with the exception of the PostgreSQL backend and possibly
+ some third-party dialects, no other SQLAlchemy built-in dialect has support
+ for this type.
An :class:`.types.ARRAY` type is constructed given the "type"
of element::
@@ -2284,8 +2290,8 @@ class ARRAY(SchemaEventTarget, Indexable, Concatenable, TypeEngine):
serves to define the kind of type that the ``[]`` operator should
return, e.g. for an ARRAY of INTEGER with two dimensions::
- >>> expr = table.c.column[5] # returns ARRAY(Integer, dimensions=1)
- >>> expr = expr[6] # returns Integer
+ >>> expr = table.c.column[5] # returns ARRAY(Integer, dimensions=1)
+ >>> expr = expr[6] # returns Integer
For 1-dimensional arrays, an :class:`.types.ARRAY` instance with no
dimension parameter will generally assume single-dimensional behaviors.
@@ -2308,9 +2314,9 @@ class ARRAY(SchemaEventTarget, Indexable, Concatenable, TypeEngine):
})
The :class:`.types.ARRAY` type also provides for the operators
- :meth:`.types.ARRAY.Comparator.any` and :meth:`.types.ARRAY.Comparator.all`.
- The PostgreSQL-specific version of :class:`.types.ARRAY` also provides additional
- operators.
+ :meth:`.types.ARRAY.Comparator.any` and
+ :meth:`.types.ARRAY.Comparator.all`. The PostgreSQL-specific version of
+ :class:`.types.ARRAY` also provides additional operators.
.. versionadded:: 1.1.0
@@ -2780,10 +2786,10 @@ _type_map = {
}
if util.py3k:
- _type_map[bytes] = LargeBinary()
+ _type_map[bytes] = LargeBinary() # noqa
_type_map[str] = Unicode()
else:
- _type_map[unicode] = Unicode()
+ _type_map[unicode] = Unicode() # noqa
_type_map[str] = String()
_type_map_get = _type_map.get
@@ -2811,8 +2817,6 @@ def _resolve_value_to_type(value):
# back-assign to type_api
-from . import type_api
-
type_api.BOOLEANTYPE = BOOLEANTYPE
type_api.STRINGTYPE = STRINGTYPE
type_api.INTEGERTYPE = INTEGERTYPE
diff --git a/lib/sqlalchemy/sql/type_api.py b/lib/sqlalchemy/sql/type_api.py
index 7fe780783..647c3e776 100644
--- a/lib/sqlalchemy/sql/type_api.py
+++ b/lib/sqlalchemy/sql/type_api.py
@@ -10,10 +10,13 @@
"""
-from .. import exc, util
from . import operators
-from .visitors import Visitable, VisitableType
from .base import SchemaEventTarget
+from .visitors import Visitable
+from .visitors import VisitableType
+from .. import exc
+from .. import util
+
# these are back-assigned by sqltypes.
BOOLEANTYPE = None
@@ -396,7 +399,7 @@ class TypeEngine(Visitable):
raise NotImplementedError()
def with_variant(self, type_, dialect_name):
- """Produce a new type object that will utilize the given
+ r"""Produce a new type object that will utilize the given
type when applied to the dialect of the given name.
e.g.::
@@ -414,7 +417,7 @@ class TypeEngine(Visitable):
itself provides a :meth:`.Variant.with_variant`
that can be called repeatedly.
- :param type_: a :class:`.TypeEngine` that will be selected
+ :param type\_: a :class:`.TypeEngine` that will be selected
as a variant from the originating type, when a dialect
of the given name is in use.
:param dialect_name: base name of the dialect which uses
@@ -592,7 +595,9 @@ class TypeEngine(Visitable):
def __str__(self):
if util.py2k:
- return unicode(self.compile()).encode("ascii", "backslashreplace")
+ return unicode(self.compile()).encode( # noqa
+ "ascii", "backslashreplace"
+ ) # noqa
else:
return str(self.compile())
@@ -1407,11 +1412,11 @@ class Variant(TypeDecorator):
impl._set_parent_with_dispatch(parent)
def with_variant(self, type_, dialect_name):
- """Return a new :class:`.Variant` which adds the given
+ r"""Return a new :class:`.Variant` which adds the given
type + dialect name to the mapping, in addition to the
mapping present in this :class:`.Variant`.
- :param type_: a :class:`.TypeEngine` that will be selected
+ :param type\_: a :class:`.TypeEngine` that will be selected
as a variant from the originating type, when a dialect
of the given name is in use.
:param dialect_name: base name of the dialect which uses
diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py
index 4feaf9938..604b3cfd9 100644
--- a/lib/sqlalchemy/sql/util.py
+++ b/lib/sqlalchemy/sql/util.py
@@ -9,41 +9,39 @@
"""
-from .. import exc, util
-from .base import _from_objects, ColumnSet
-from . import operators, visitors
-from itertools import chain
from collections import deque
+from itertools import chain
-from .elements import (
- BindParameter,
- ColumnClause,
- ColumnElement,
- Null,
- UnaryExpression,
- literal_column,
- Label,
- _label_reference,
- _textual_label_reference,
-)
-from .selectable import (
- SelectBase,
- ScalarSelect,
- Join,
- FromClause,
- FromGrouping,
-)
+from . import operators
+from . import visitors
+from .annotation import _deep_annotate # noqa
+from .annotation import _deep_deannotate # noqa
+from .annotation import _shallow_annotate # noqa
+from .base import _from_objects
+from .base import ColumnSet
+from .ddl import sort_tables # noqa
+from .elements import _find_columns # noqa
+from .elements import _label_reference
+from .elements import _textual_label_reference
+from .elements import BindParameter
+from .elements import ColumnClause
+from .elements import ColumnElement
+from .elements import Null
+from .elements import UnaryExpression
from .schema import Column
+from .selectable import FromClause
+from .selectable import FromGrouping
+from .selectable import Join
+from .selectable import ScalarSelect
+from .selectable import SelectBase
+from .. import exc
+from .. import util
+
join_condition = util.langhelpers.public_factory(
Join._join_condition, ".sql.util.join_condition"
)
-# names that are still being imported from the outside
-from .annotation import _shallow_annotate, _deep_annotate, _deep_deannotate
-from .elements import _find_columns
-from .ddl import sort_tables
-
def find_join_source(clauses, join_to):
"""Given a list of FROM clauses and a selectable,
diff --git a/lib/sqlalchemy/sql/visitors.py b/lib/sqlalchemy/sql/visitors.py
index bf1743643..d4b72dd59 100644
--- a/lib/sqlalchemy/sql/visitors.py
+++ b/lib/sqlalchemy/sql/visitors.py
@@ -25,9 +25,11 @@ http://techspot.zzzeek.org/2008/01/23/expression-transformations/
"""
from collections import deque
-from .. import util
import operator
+
from .. import exc
+from .. import util
+
__all__ = [
"VisitableType",
diff --git a/lib/sqlalchemy/testing/__init__.py b/lib/sqlalchemy/testing/__init__.py
index f46ca4528..e41c3addf 100644
--- a/lib/sqlalchemy/testing/__init__.py
+++ b/lib/sqlalchemy/testing/__init__.py
@@ -6,70 +6,58 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .warnings import assert_warnings
-
-from . import config
-
-from .exclusions import (
- db_spec,
- _is_excluded,
- fails_if,
- skip_if,
- future,
- fails_on,
- fails_on_everything_except,
- skip,
- only_on,
- exclude,
- against as _against,
- _server_version,
- only_if,
- fails,
-)
+from . import config # noqa
+from . import mock # noqa
+from .assertions import assert_raises # noqa
+from .assertions import assert_raises_message # noqa
+from .assertions import AssertsCompiledSQL # noqa
+from .assertions import AssertsExecutionResults # noqa
+from .assertions import ComparesTables # noqa
+from .assertions import emits_warning # noqa
+from .assertions import emits_warning_on # noqa
+from .assertions import eq_ # noqa
+from .assertions import eq_ignore_whitespace # noqa
+from .assertions import eq_regex # noqa
+from .assertions import expect_deprecated # noqa
+from .assertions import expect_warnings # noqa
+from .assertions import in_ # noqa
+from .assertions import is_ # noqa
+from .assertions import is_false # noqa
+from .assertions import is_not_ # noqa
+from .assertions import is_true # noqa
+from .assertions import le_ # noqa
+from .assertions import ne_ # noqa
+from .assertions import not_in_ # noqa
+from .assertions import startswith_ # noqa
+from .assertions import uses_deprecated # noqa
+from .config import db # noqa
+from .config import requirements as requires # noqa
+from .exclusions import _is_excluded # noqa
+from .exclusions import _server_version # noqa
+from .exclusions import against as _against # noqa
+from .exclusions import db_spec # noqa
+from .exclusions import exclude # noqa
+from .exclusions import fails # noqa
+from .exclusions import fails_if # noqa
+from .exclusions import fails_on # noqa
+from .exclusions import fails_on_everything_except # noqa
+from .exclusions import future # noqa
+from .exclusions import only_if # noqa
+from .exclusions import only_on # noqa
+from .exclusions import skip # noqa
+from .exclusions import skip_if # noqa
+from .util import adict # noqa
+from .util import fail # noqa
+from .util import force_drop_names # noqa
+from .util import provide_metadata # noqa
+from .util import rowset # noqa
+from .util import run_as_contextmanager # noqa
+from .util import teardown_events # noqa
+from .warnings import assert_warnings # noqa
def against(*queries):
return _against(config._current, *queries)
-from .assertions import (
- emits_warning,
- emits_warning_on,
- uses_deprecated,
- eq_,
- ne_,
- le_,
- is_,
- is_not_,
- startswith_,
- assert_raises,
- assert_raises_message,
- AssertsCompiledSQL,
- ComparesTables,
- AssertsExecutionResults,
- expect_deprecated,
- expect_warnings,
- in_,
- not_in_,
- eq_ignore_whitespace,
- eq_regex,
- is_true,
- is_false,
-)
-
-from .util import (
- run_as_contextmanager,
- rowset,
- fail,
- provide_metadata,
- adict,
- force_drop_names,
- teardown_events,
-)
-
crashes = skip
-
-from .config import db
-from .config import requirements as requires
-
-from . import mock
diff --git a/lib/sqlalchemy/testing/assertions.py b/lib/sqlalchemy/testing/assertions.py
index 73ab4556a..11b77d72a 100644
--- a/lib/sqlalchemy/testing/assertions.py
+++ b/lib/sqlalchemy/testing/assertions.py
@@ -7,19 +7,26 @@
from __future__ import absolute_import
-from . import util as testutil
-from sqlalchemy import pool, orm, util
-from sqlalchemy.engine import default, url
-from sqlalchemy.util import decorator, compat
-from sqlalchemy import types as sqltypes, schema, exc as sa_exc
-import warnings
+import contextlib
import re
-from .exclusions import db_spec
+import warnings
+
from . import assertsql
from . import config
-from .util import fail
-import contextlib
from . import mock
+from . import util as testutil
+from .exclusions import db_spec
+from .util import fail
+from .. import exc as sa_exc
+from .. import orm
+from .. import pool
+from .. import schema
+from .. import types as sqltypes
+from .. import util
+from ..engine import default
+from ..engine import url
+from ..util import compat
+from ..util import decorator
def expect_warnings(*messages, **kw):
@@ -442,15 +449,15 @@ class AssertsExecutionResults(object):
print(repr(result))
self.assert_list(result, class_, objects)
- def assert_list(self, result, class_, list):
+ def assert_list(self, result, class_, list_):
self.assert_(
- len(result) == len(list),
+ len(result) == len(list_),
"result list is not the same size as test list, "
+ "for class "
+ class_.__name__,
)
- for i in range(0, len(list)):
- self.assert_row(class_, result[i], list[i])
+ for i in range(0, len(list_)):
+ self.assert_row(class_, result[i], list_[i])
def assert_row(self, class_, rowobj, desc):
self.assert_(
diff --git a/lib/sqlalchemy/testing/assertsql.py b/lib/sqlalchemy/testing/assertsql.py
index d8e924cb6..1d3cfe0e1 100644
--- a/lib/sqlalchemy/testing/assertsql.py
+++ b/lib/sqlalchemy/testing/assertsql.py
@@ -5,15 +5,16 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from ..engine.default import DefaultDialect
-from .. import util
-import re
import collections
import contextlib
+import re
+
from .. import event
-from sqlalchemy.schema import _DDLCompiles
-from sqlalchemy.engine.util import _distill_params
-from sqlalchemy.engine import url
+from .. import util
+from ..engine import url
+from ..engine.default import DefaultDialect
+from ..engine.util import _distill_params
+from ..schema import _DDLCompiles
class AssertRule(object):
diff --git a/lib/sqlalchemy/testing/engines.py b/lib/sqlalchemy/testing/engines.py
index 074e3b338..bfb1a24b5 100644
--- a/lib/sqlalchemy/testing/engines.py
+++ b/lib/sqlalchemy/testing/engines.py
@@ -7,12 +7,14 @@
from __future__ import absolute_import
+import re
+import warnings
import weakref
+
from . import config
from .util import decorator
-from .. import event, pool
-import re
-import warnings
+from .. import event
+from .. import pool
class ConnectionKiller(object):
diff --git a/lib/sqlalchemy/testing/entities.py b/lib/sqlalchemy/testing/entities.py
index 42c42149c..a14304b97 100644
--- a/lib/sqlalchemy/testing/entities.py
+++ b/lib/sqlalchemy/testing/entities.py
@@ -6,7 +6,8 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
import sqlalchemy as sa
-from sqlalchemy import exc as sa_exc
+from .. import exc as sa_exc
+
_repr_stack = set()
diff --git a/lib/sqlalchemy/testing/exclusions.py b/lib/sqlalchemy/testing/exclusions.py
index 9ed9e42c3..ffca84af1 100644
--- a/lib/sqlalchemy/testing/exclusions.py
+++ b/lib/sqlalchemy/testing/exclusions.py
@@ -10,11 +10,10 @@ import contextlib
import operator
import re
-from sqlalchemy.util.compat import inspect_getargspec
-
from . import config
from .. import util
from ..util import decorator
+from ..util.compat import inspect_getargspec
def skip_if(predicate, reason=None):
@@ -399,7 +398,7 @@ def db_spec(*dbs):
return OrPredicate([Predicate.as_predicate(db) for db in dbs])
-def open():
+def open(): # noqa
return skip_if(BooleanPredicate(False, "mark as execute"))
diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py
index 98184cdd4..b0f3590ee 100644
--- a/lib/sqlalchemy/testing/fixtures.py
+++ b/lib/sqlalchemy/testing/fixtures.py
@@ -5,15 +5,21 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
+import sys
+
+import sqlalchemy as sa
+from . import assertions
from . import config
-from . import assertions, schema
+from . import schema
+from .engines import drop_all_tables
+from .entities import BasicEntity
+from .entities import ComparableEntity
from .util import adict
+from .. import event
from .. import util
-from .engines import drop_all_tables
-from .entities import BasicEntity, ComparableEntity
-import sys
-import sqlalchemy as sa
-from sqlalchemy.ext.declarative import declarative_base, DeclarativeMeta
+from ..ext.declarative import declarative_base
+from ..ext.declarative import DeclarativeMeta
+
# whether or not we use unittest changes things dramatically,
# as far as how py.test collection works.
@@ -220,9 +226,6 @@ class TablesTest(TestBase):
)
-from sqlalchemy import event
-
-
class RemovesEvents(object):
@util.memoized_property
def _event_fns(self):
diff --git a/lib/sqlalchemy/testing/mock.py b/lib/sqlalchemy/testing/mock.py
index dc530af5e..0b84d7db8 100644
--- a/lib/sqlalchemy/testing/mock.py
+++ b/lib/sqlalchemy/testing/mock.py
@@ -8,13 +8,23 @@
"""Import stub for mock library.
"""
from __future__ import absolute_import
+
from ..util import py33
+
if py33:
- from unittest.mock import MagicMock, Mock, call, patch, ANY
+ from unittest.mock import MagicMock
+ from unittest.mock import Mock
+ from unittest.mock import call
+ from unittest.mock import patch
+ from unittest.mock import ANY
else:
try:
- from mock import MagicMock, Mock, call, patch, ANY
+ from mock import MagicMock # noqa
+ from mock import Mock # noqa
+ from mock import call # noqa
+ from mock import patch # noqa
+ from mock import ANY # noqa
except ImportError:
raise ImportError(
"SQLAlchemy's test suite requires the "
diff --git a/lib/sqlalchemy/testing/plugin/bootstrap.py b/lib/sqlalchemy/testing/plugin/bootstrap.py
index bb52c125c..2230ae2a8 100644
--- a/lib/sqlalchemy/testing/plugin/bootstrap.py
+++ b/lib/sqlalchemy/testing/plugin/bootstrap.py
@@ -20,6 +20,7 @@ this should be removable when Alembic targets SQLAlchemy 1.0.0.
import os
import sys
+
bootstrap_file = locals()["bootstrap_file"]
to_bootstrap = locals()["to_bootstrap"]
diff --git a/lib/sqlalchemy/testing/plugin/noseplugin.py b/lib/sqlalchemy/testing/plugin/noseplugin.py
index 0c28a5213..07185a9d7 100644
--- a/lib/sqlalchemy/testing/plugin/noseplugin.py
+++ b/lib/sqlalchemy/testing/plugin/noseplugin.py
@@ -23,8 +23,9 @@ except ImportError:
import os
import sys
-from nose.plugins import Plugin
import nose
+from nose.plugins import Plugin
+
fixtures = None
diff --git a/lib/sqlalchemy/testing/plugin/plugin_base.py b/lib/sqlalchemy/testing/plugin/plugin_base.py
index 5d6bf2975..537ab06dc 100644
--- a/lib/sqlalchemy/testing/plugin/plugin_base.py
+++ b/lib/sqlalchemy/testing/plugin/plugin_base.py
@@ -15,8 +15,9 @@ functionality via py.test.
from __future__ import absolute_import
-import sys
import re
+import sys
+
py3k = sys.version_info >= (3, 0)
@@ -245,7 +246,8 @@ def post_begin():
# late imports, has to happen after config as well
# as nose plugins like coverage
- global util, fixtures, engines, exclusions, assertions, warnings, profiling, config, testing
+ global util, fixtures, engines, exclusions, assertions
+ global warnings, profiling, config, testing
from sqlalchemy import testing # noqa
from sqlalchemy.testing import fixtures, engines, exclusions # noqa
from sqlalchemy.testing import assertions, warnings, profiling # noqa
@@ -525,8 +527,8 @@ def generate_sub_tests(cls, module):
# pytest junit plugin, which is tripped up by the brackets
# and periods, so sanitize
- alpha_name = re.sub("[_\[\]\.]+", "_", cfg.name)
- alpha_name = re.sub("_+$", "", alpha_name)
+ alpha_name = re.sub(r"[_\[\]\.]+", "_", cfg.name)
+ alpha_name = re.sub(r"_+$", "", alpha_name)
name = "%s_%s" % (cls.__name__, alpha_name)
subcls = type(
name,
diff --git a/lib/sqlalchemy/testing/plugin/pytestplugin.py b/lib/sqlalchemy/testing/plugin/pytestplugin.py
index fd0a48462..f42fc4791 100644
--- a/lib/sqlalchemy/testing/plugin/pytestplugin.py
+++ b/lib/sqlalchemy/testing/plugin/pytestplugin.py
@@ -5,12 +5,14 @@ except ImportError:
# assume we're a package, use traditional import
from . import plugin_base
-import pytest
import argparse
-import inspect
import collections
+import inspect
import os
+import pytest
+
+
try:
import xdist # noqa
@@ -44,7 +46,7 @@ def pytest_addoption(parser):
dest,
default=False,
required=False,
- help=None,
+ help=None, # noqa
):
super(CallableAction, self).__init__(
option_strings=option_strings,
diff --git a/lib/sqlalchemy/testing/profiling.py b/lib/sqlalchemy/testing/profiling.py
index 3986985c7..753cfa595 100644
--- a/lib/sqlalchemy/testing/profiling.py
+++ b/lib/sqlalchemy/testing/profiling.py
@@ -12,19 +12,24 @@ in a more fine-grained way than nose's profiling plugin.
"""
+import collections
+import contextlib
import os
+import pstats
import sys
-from .util import gc_collect
+
from . import config
-import pstats
-import collections
-import contextlib
+from .util import gc_collect
+from ..util import jython
+from ..util import pypy
+from ..util import update_wrapper
+from ..util import win32
+
try:
import cProfile
except ImportError:
cProfile = None
-from ..util import jython, pypy, win32, update_wrapper
_current_test = None
diff --git a/lib/sqlalchemy/testing/provision.py b/lib/sqlalchemy/testing/provision.py
index 25028ccb3..88dc28528 100644
--- a/lib/sqlalchemy/testing/provision.py
+++ b/lib/sqlalchemy/testing/provision.py
@@ -1,13 +1,16 @@
-from sqlalchemy.engine import url as sa_url
-from sqlalchemy import create_engine
-from sqlalchemy import text
-from sqlalchemy import exc
-from sqlalchemy.util import compat
-from . import config, engines
import collections
+import logging
import os
import time
-import logging
+
+from . import config
+from . import engines
+from .. import create_engine
+from .. import exc
+from .. import text
+from ..engine import url as sa_url
+from ..util import compat
+
log = logging.getLogger(__name__)
@@ -190,6 +193,8 @@ def _pg_create_db(cfg, eng, ident):
template_db,
)
time.sleep(0.5)
+ except:
+ raise
else:
break
@@ -395,7 +400,8 @@ def _mssql_drop_ignore(conn, ident):
try:
# typically when this happens, we can't KILL the session anyway,
# so let the cleanup process drop the DBs
- # for row in conn.execute("select session_id from sys.dm_exec_sessions "
+ # for row in conn.execute(
+ # "select session_id from sys.dm_exec_sessions "
# "where database_id=db_id('%s')" % ident):
# log.info("killing SQL server sesssion %s", row['session_id'])
# conn.execute("kill %s" % row['session_id'])
diff --git a/lib/sqlalchemy/testing/replay_fixture.py b/lib/sqlalchemy/testing/replay_fixture.py
index 9832b07a2..613d7572b 100644
--- a/lib/sqlalchemy/testing/replay_fixture.py
+++ b/lib/sqlalchemy/testing/replay_fixture.py
@@ -1,13 +1,14 @@
-from . import fixtures
-from . import profiling
-from .. import util
-import types
from collections import deque
import contextlib
+import types
+
from . import config
-from sqlalchemy import MetaData
-from sqlalchemy import create_engine
-from sqlalchemy.orm import Session
+from . import fixtures
+from . import profiling
+from .. import create_engine
+from .. import MetaData
+from .. import util
+from ..orm import Session
class ReplayFixtureTest(fixtures.TestBase):
@@ -19,7 +20,10 @@ class ReplayFixtureTest(fixtures.TestBase):
dbapi_session = ReplayableSession()
creator = config.db.pool._creator
- recorder = lambda: dbapi_session.recorder(creator())
+
+ def recorder():
+ return dbapi_session.recorder(creator())
+
engine = create_engine(
config.db.url, creator=recorder, use_native_hstore=False
)
@@ -34,7 +38,9 @@ class ReplayFixtureTest(fixtures.TestBase):
self.teardown_engine()
engine.dispose()
- player = lambda: dbapi_session.player()
+ def player():
+ return dbapi_session.player()
+
engine = create_engine(
config.db.url, creator=player, use_native_hstore=False
)
diff --git a/lib/sqlalchemy/testing/requirements.py b/lib/sqlalchemy/testing/requirements.py
index c96d26d32..941a9458b 100644
--- a/lib/sqlalchemy/testing/requirements.py
+++ b/lib/sqlalchemy/testing/requirements.py
@@ -243,7 +243,9 @@ class SuiteRequirements(Requirements):
@property
def sane_rowcount_w_returning(self):
return exclusions.fails_if(
- lambda config: not config.db.dialect.supports_sane_rowcount_returning,
+ lambda config: not (
+ config.db.dialect.supports_sane_rowcount_returning
+ ),
"driver doesn't support 'sane' rowcount when returning is on",
)
@@ -758,12 +760,13 @@ class SuiteRequirements(Requirements):
present in a subquery in the WHERE clause.
This is an ANSI-standard syntax that apparently MySQL can't handle,
- such as:
+ such as::
+
+ UPDATE documents SET flag=1 WHERE documents.title IN
+ (SELECT max(documents.title) AS title
+ FROM documents GROUP BY documents.user_id
+ )
- UPDATE documents SET flag=1 WHERE documents.title IN
- (SELECT max(documents.title) AS title
- FROM documents GROUP BY documents.user_id
- )
"""
return exclusions.open()
@@ -944,7 +947,7 @@ class SuiteRequirements(Requirements):
def _has_cextensions(self):
try:
- from sqlalchemy import cresultproxy, cprocessors
+ from sqlalchemy import cresultproxy, cprocessors # noqa
return True
except ImportError:
diff --git a/lib/sqlalchemy/testing/runner.py b/lib/sqlalchemy/testing/runner.py
index 6aa820fd5..b4478bedc 100644
--- a/lib/sqlalchemy/testing/runner.py
+++ b/lib/sqlalchemy/testing/runner.py
@@ -30,10 +30,10 @@ SQLAlchemy itself is possible.
"""
-from .plugin.noseplugin import NoseSQLAlchemy
-
import nose
+from .plugin.noseplugin import NoseSQLAlchemy
+
def main():
nose.main(addplugins=[NoseSQLAlchemy()])
diff --git a/lib/sqlalchemy/testing/schema.py b/lib/sqlalchemy/testing/schema.py
index b345a9487..c80325b7c 100644
--- a/lib/sqlalchemy/testing/schema.py
+++ b/lib/sqlalchemy/testing/schema.py
@@ -5,11 +5,13 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from . import exclusions
-from .. import schema, event
from . import config
+from . import exclusions
+from .. import event
+from .. import schema
+
-__all__ = "Table", "Column"
+__all__ = ["Table", "Column"]
table_options = {}
diff --git a/lib/sqlalchemy/testing/suite/__init__.py b/lib/sqlalchemy/testing/suite/__init__.py
index a4e142c5a..465a6cfc5 100644
--- a/lib/sqlalchemy/testing/suite/__init__.py
+++ b/lib/sqlalchemy/testing/suite/__init__.py
@@ -1,10 +1,10 @@
-from sqlalchemy.testing.suite.test_cte import *
-from sqlalchemy.testing.suite.test_dialect import *
-from sqlalchemy.testing.suite.test_ddl import *
-from sqlalchemy.testing.suite.test_insert import *
-from sqlalchemy.testing.suite.test_sequence import *
-from sqlalchemy.testing.suite.test_select import *
-from sqlalchemy.testing.suite.test_results import *
-from sqlalchemy.testing.suite.test_update_delete import *
-from sqlalchemy.testing.suite.test_reflection import *
-from sqlalchemy.testing.suite.test_types import *
+from .test_cte import * # noqa
+from .test_ddl import * # noqa
+from .test_dialect import * # noqa
+from .test_insert import * # noqa
+from .test_reflection import * # noqa
+from .test_results import * # noqa
+from .test_select import * # noqa
+from .test_sequence import * # noqa
+from .test_types import * # noqa
+from .test_update_delete import * # noqa
diff --git a/lib/sqlalchemy/testing/suite/test_cte.py b/lib/sqlalchemy/testing/suite/test_cte.py
index d2f35933b..012de7911 100644
--- a/lib/sqlalchemy/testing/suite/test_cte.py
+++ b/lib/sqlalchemy/testing/suite/test_cte.py
@@ -1,11 +1,13 @@
-from .. import fixtures, config
+from .. import config
+from .. import fixtures
from ..assertions import eq_
-
-from sqlalchemy import Integer, String, select
-from sqlalchemy import ForeignKey
-from sqlalchemy import testing
-
-from ..schema import Table, Column
+from ..schema import Column
+from ..schema import Table
+from ... import ForeignKey
+from ... import Integer
+from ... import select
+from ... import String
+from ... import testing
class CTETest(fixtures.TablesTest):
diff --git a/lib/sqlalchemy/testing/suite/test_ddl.py b/lib/sqlalchemy/testing/suite/test_ddl.py
index 7c44388d4..8317590c8 100644
--- a/lib/sqlalchemy/testing/suite/test_ddl.py
+++ b/lib/sqlalchemy/testing/suite/test_ddl.py
@@ -1,8 +1,12 @@
-from .. import fixtures, config, util
-from ..config import requirements
+from .. import config
+from .. import fixtures
+from .. import util
from ..assertions import eq_
-
-from sqlalchemy import Table, Column, Integer, String
+from ..config import requirements
+from ... import Column
+from ... import Integer
+from ... import String
+from ... import Table
class TableDDLTest(fixtures.TestBase):
diff --git a/lib/sqlalchemy/testing/suite/test_dialect.py b/lib/sqlalchemy/testing/suite/test_dialect.py
index 5e589f3b8..245ccc6f0 100644
--- a/lib/sqlalchemy/testing/suite/test_dialect.py
+++ b/lib/sqlalchemy/testing/suite/test_dialect.py
@@ -1,11 +1,16 @@
-from .. import fixtures, config
-from ..config import requirements
-from sqlalchemy import exc
-from sqlalchemy import Integer, String, select, literal_column
from .. import assert_raises
-from ..schema import Table, Column
-from .. import provide_metadata
+from .. import config
from .. import eq_
+from .. import fixtures
+from .. import provide_metadata
+from ..config import requirements
+from ..schema import Column
+from ..schema import Table
+from ... import exc
+from ... import Integer
+from ... import literal_column
+from ... import select
+from ... import String
class ExceptionTest(fixtures.TablesTest):
diff --git a/lib/sqlalchemy/testing/suite/test_insert.py b/lib/sqlalchemy/testing/suite/test_insert.py
index 6257451eb..1b14e8ed8 100644
--- a/lib/sqlalchemy/testing/suite/test_insert.py
+++ b/lib/sqlalchemy/testing/suite/test_insert.py
@@ -1,12 +1,15 @@
-from .. import fixtures, config
-from ..config import requirements
-from .. import exclusions
-from ..assertions import eq_
+from .. import config
from .. import engines
-
-from sqlalchemy import Integer, String, select, literal_column, literal
-
-from ..schema import Table, Column
+from .. import fixtures
+from ..assertions import eq_
+from ..config import requirements
+from ..schema import Column
+from ..schema import Table
+from ... import Integer
+from ... import literal
+from ... import literal_column
+from ... import select
+from ... import String
class LastrowidTest(fixtures.TablesTest):
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py
index bfed5f1ab..96bd188ee 100644
--- a/lib/sqlalchemy/testing/suite/test_reflection.py
+++ b/lib/sqlalchemy/testing/suite/test_reflection.py
@@ -1,21 +1,30 @@
-import sqlalchemy as sa
-from sqlalchemy import exc as sa_exc
-from sqlalchemy import types as sql_types
-from sqlalchemy import inspect
-from sqlalchemy import MetaData, Integer, String, func
-from sqlalchemy.engine.reflection import Inspector
-from sqlalchemy.testing import engines, fixtures
-from sqlalchemy.testing.schema import Table, Column
-from sqlalchemy.testing import eq_, is_, assert_raises_message
-from sqlalchemy import testing
-from .. import config
import operator
-from sqlalchemy.schema import DDL, Index
-from sqlalchemy import event
-from sqlalchemy.sql.elements import quoted_name
-from sqlalchemy import ForeignKey
import re
+import sqlalchemy as sa
+from .. import assert_raises_message
+from .. import config
+from .. import engines
+from .. import eq_
+from .. import fixtures
+from .. import is_
+from ..schema import Column
+from ..schema import Table
+from ... import event
+from ... import exc as sa_exc
+from ... import ForeignKey
+from ... import inspect
+from ... import Integer
+from ... import MetaData
+from ... import String
+from ... import testing
+from ... import types as sql_types
+from ...engine.reflection import Inspector
+from ...schema import DDL
+from ...schema import Index
+from ...sql.elements import quoted_name
+
+
metadata, users = None, None
@@ -367,7 +376,9 @@ class ComponentReflectionTest(fixtures.TablesTest):
{"comment": "id comment", "name": "id"},
{"comment": "data % comment", "name": "data"},
{
- "comment": r"""Comment types type speedily ' " \ '' Fun!""",
+ "comment": (
+ r"""Comment types type speedily ' " \ '' Fun!"""
+ ),
"name": "d2",
},
],
diff --git a/lib/sqlalchemy/testing/suite/test_results.py b/lib/sqlalchemy/testing/suite/test_results.py
index 247f05cf5..aa98a5088 100644
--- a/lib/sqlalchemy/testing/suite/test_results.py
+++ b/lib/sqlalchemy/testing/suite/test_results.py
@@ -1,13 +1,20 @@
-from .. import fixtures, config
-from ..config import requirements
-from .. import exclusions
-from ..assertions import eq_
+import datetime
+
+from .. import config
from .. import engines
+from .. import fixtures
+from ..assertions import eq_
+from ..config import requirements
+from ..schema import Column
+from ..schema import Table
+from ... import DateTime
+from ... import func
+from ... import Integer
+from ... import select
+from ... import sql
+from ... import String
from ... import testing
-
-from sqlalchemy import Integer, String, select, util, sql, DateTime, text, func
-import datetime
-from ..schema import Table, Column
+from ... import text
class RowFetchTest(fixtures.TablesTest):
diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py
index 032b68eb6..d26585141 100644
--- a/lib/sqlalchemy/testing/suite/test_select.py
+++ b/lib/sqlalchemy/testing/suite/test_select.py
@@ -1,14 +1,23 @@
-from sqlalchemy.dialects.mssql.base import MSDialect
-from sqlalchemy.dialects.oracle.base import OracleDialect
-from .. import fixtures, config
-from ..assertions import eq_, in_
-
-from sqlalchemy import util, case, null, true, false, or_
-from sqlalchemy import Integer, String, select, func, bindparam, union, tuple_
-from sqlalchemy import testing
-from sqlalchemy import literal_column
-
-from ..schema import Table, Column
+from .. import config
+from .. import fixtures
+from ..assertions import eq_
+from ..assertions import in_
+from ..schema import Column
+from ..schema import Table
+from ... import bindparam
+from ... import case
+from ... import false
+from ... import func
+from ... import Integer
+from ... import literal_column
+from ... import null
+from ... import select
+from ... import String
+from ... import testing
+from ... import true
+from ... import tuple_
+from ... import union
+from ... import util
class CollateTest(fixtures.TablesTest):
diff --git a/lib/sqlalchemy/testing/suite/test_sequence.py b/lib/sqlalchemy/testing/suite/test_sequence.py
index 15a850fe9..22ae7d43c 100644
--- a/lib/sqlalchemy/testing/suite/test_sequence.py
+++ b/lib/sqlalchemy/testing/suite/test_sequence.py
@@ -1,12 +1,16 @@
-from .. import fixtures, config
-from ..config import requirements
+from .. import config
+from .. import fixtures
from ..assertions import eq_
+from ..config import requirements
+from ..schema import Column
+from ..schema import Table
+from ... import Integer
+from ... import MetaData
+from ... import schema
+from ... import Sequence
+from ... import String
from ... import testing
-from ... import Integer, String, Sequence, schema, MetaData
-
-from ..schema import Table, Column
-
class SequenceTest(fixtures.TablesTest):
__requires__ = ("sequences",)
diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py
index 6dfb80915..ff8db5897 100644
--- a/lib/sqlalchemy/testing/suite/test_types.py
+++ b/lib/sqlalchemy/testing/suite/test_types.py
@@ -1,33 +1,40 @@
# coding: utf-8
-from .. import fixtures, config
+import datetime
+import decimal
+
+from .. import config
+from .. import fixtures
from ..assertions import eq_
from ..config import requirements
-from sqlalchemy import Integer, Unicode, UnicodeText, select, TIMESTAMP
-from sqlalchemy import (
- Date,
- DateTime,
- Time,
- MetaData,
- String,
- Text,
- Numeric,
- Float,
- literal,
- Boolean,
- cast,
- null,
- JSON,
- and_,
- type_coerce,
- BigInteger,
-)
-from ..schema import Table, Column
+from ..schema import Column
+from ..schema import Table
+from ... import and_
+from ... import BigInteger
+from ... import Boolean
+from ... import cast
+from ... import Date
+from ... import DateTime
+from ... import Float
+from ... import Integer
+from ... import JSON
+from ... import literal
+from ... import MetaData
+from ... import null
+from ... import Numeric
+from ... import select
+from ... import String
from ... import testing
-import decimal
-import datetime
-from ...util import u
+from ... import Text
+from ... import Time
+from ... import TIMESTAMP
+from ... import type_coerce
+from ... import Unicode
+from ... import UnicodeText
from ... import util
+from ...ext.declarative import declarative_base
+from ...orm import Session
+from ...util import u
class _LiteralRoundTripFixture(object):
@@ -341,7 +348,7 @@ class IntegerTest(_LiteralRoundTripFixture, fixtures.TestBase):
if util.py3k:
assert isinstance(row[0], int)
else:
- assert isinstance(row[0], (long, int))
+ assert isinstance(row[0], (long, int)) # noqa
class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
@@ -872,8 +879,6 @@ class JSONTest(_LiteralRoundTripFixture, fixtures.TablesTest):
)
def test_eval_none_flag_orm(self):
- from sqlalchemy.ext.declarative import declarative_base
- from sqlalchemy.orm import Session
Base = declarative_base()
diff --git a/lib/sqlalchemy/testing/suite/test_update_delete.py b/lib/sqlalchemy/testing/suite/test_update_delete.py
index b232c3a78..97bdf0ad7 100644
--- a/lib/sqlalchemy/testing/suite/test_update_delete.py
+++ b/lib/sqlalchemy/testing/suite/test_update_delete.py
@@ -1,8 +1,10 @@
-from .. import fixtures, config
+from .. import config
+from .. import fixtures
from ..assertions import eq_
-
-from sqlalchemy import Integer, String
-from ..schema import Table, Column
+from ..schema import Column
+from ..schema import Table
+from ... import Integer
+from ... import String
class SimpleUpdateDeleteTest(fixtures.TablesTest):
diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py
index 5b015d214..214afa078 100644
--- a/lib/sqlalchemy/testing/util.py
+++ b/lib/sqlalchemy/testing/util.py
@@ -5,14 +5,20 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from ..util import jython, pypy, defaultdict, decorator, py2k
import decimal
import gc
-import time
import random
import sys
+import time
import types
+from ..util import decorator
+from ..util import defaultdict
+from ..util import jython
+from ..util import py2k
+from ..util import pypy
+
+
if jython:
def jython_gc_collect(*args):
diff --git a/lib/sqlalchemy/testing/warnings.py b/lib/sqlalchemy/testing/warnings.py
index e0101b14d..611389fe0 100644
--- a/lib/sqlalchemy/testing/warnings.py
+++ b/lib/sqlalchemy/testing/warnings.py
@@ -8,8 +8,9 @@
from __future__ import absolute_import
import warnings
-from .. import exc as sa_exc
+
from . import assertions
+from .. import exc as sa_exc
def setup_filters():
diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py
index e66582801..4cdc18d97 100644
--- a/lib/sqlalchemy/types.py
+++ b/lib/sqlalchemy/types.py
@@ -59,63 +59,59 @@ __all__ = [
"JSON",
]
-from .sql.type_api import (
- adapt_type,
- TypeEngine,
- TypeDecorator,
- Variant,
- to_instance,
- UserDefinedType,
-)
-from .sql.sqltypes import (
- ARRAY,
- BIGINT,
- BINARY,
- BLOB,
- BOOLEAN,
- BigInteger,
- Binary,
- _Binary,
- Boolean,
- CHAR,
- CLOB,
- Concatenable,
- DATE,
- DATETIME,
- DECIMAL,
- Date,
- DateTime,
- Enum,
- FLOAT,
- Float,
- Indexable,
- INT,
- INTEGER,
- Integer,
- Interval,
- JSON,
- LargeBinary,
- MatchType,
- NCHAR,
- NVARCHAR,
- NullType,
- NULLTYPE,
- NUMERIC,
- Numeric,
- PickleType,
- REAL,
- SchemaType,
- SMALLINT,
- SmallInteger,
- String,
- STRINGTYPE,
- TEXT,
- TIME,
- TIMESTAMP,
- Text,
- Time,
- Unicode,
- UnicodeText,
- VARBINARY,
- VARCHAR,
-)
+from .sql.sqltypes import _Binary # noqa
+from .sql.sqltypes import ARRAY # noqa
+from .sql.sqltypes import BIGINT # noqa
+from .sql.sqltypes import BigInteger # noqa
+from .sql.sqltypes import BINARY # noqa
+from .sql.sqltypes import Binary # noqa
+from .sql.sqltypes import BLOB # noqa
+from .sql.sqltypes import BOOLEAN # noqa
+from .sql.sqltypes import Boolean # noqa
+from .sql.sqltypes import CHAR # noqa
+from .sql.sqltypes import CLOB # noqa
+from .sql.sqltypes import Concatenable # noqa
+from .sql.sqltypes import DATE # noqa
+from .sql.sqltypes import Date # noqa
+from .sql.sqltypes import DATETIME # noqa
+from .sql.sqltypes import DateTime # noqa
+from .sql.sqltypes import DECIMAL # noqa
+from .sql.sqltypes import Enum # noqa
+from .sql.sqltypes import FLOAT # noqa
+from .sql.sqltypes import Float # noqa
+from .sql.sqltypes import Indexable # noqa
+from .sql.sqltypes import INT # noqa
+from .sql.sqltypes import INTEGER # noqa
+from .sql.sqltypes import Integer # noqa
+from .sql.sqltypes import Interval # noqa
+from .sql.sqltypes import JSON # noqa
+from .sql.sqltypes import LargeBinary # noqa
+from .sql.sqltypes import MatchType # noqa
+from .sql.sqltypes import NCHAR # noqa
+from .sql.sqltypes import NULLTYPE # noqa
+from .sql.sqltypes import NullType # noqa
+from .sql.sqltypes import NUMERIC # noqa
+from .sql.sqltypes import Numeric # noqa
+from .sql.sqltypes import NVARCHAR # noqa
+from .sql.sqltypes import PickleType # noqa
+from .sql.sqltypes import REAL # noqa
+from .sql.sqltypes import SchemaType # noqa
+from .sql.sqltypes import SMALLINT # noqa
+from .sql.sqltypes import SmallInteger # noqa
+from .sql.sqltypes import String # noqa
+from .sql.sqltypes import STRINGTYPE # noqa
+from .sql.sqltypes import TEXT # noqa
+from .sql.sqltypes import Text # noqa
+from .sql.sqltypes import TIME # noqa
+from .sql.sqltypes import Time # noqa
+from .sql.sqltypes import TIMESTAMP # noqa
+from .sql.sqltypes import Unicode # noqa
+from .sql.sqltypes import UnicodeText # noqa
+from .sql.sqltypes import VARBINARY # noqa
+from .sql.sqltypes import VARCHAR # noqa
+from .sql.type_api import adapt_type # noqa
+from .sql.type_api import to_instance # noqa
+from .sql.type_api import TypeDecorator # noqa
+from .sql.type_api import TypeEngine # noqa
+from .sql.type_api import UserDefinedType # noqa
+from .sql.type_api import Variant # noqa
diff --git a/lib/sqlalchemy/util/__init__.py b/lib/sqlalchemy/util/__init__.py
index 103225e2a..13bcc37e7 100644
--- a/lib/sqlalchemy/util/__init__.py
+++ b/lib/sqlalchemy/util/__init__.py
@@ -5,150 +5,142 @@
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-from .compat import (
- callable,
- cmp,
- reduce,
- threading,
- py3k,
- py33,
- py36,
- py2k,
- jython,
- pypy,
- cpython,
- win32,
- pickle,
- dottedgetter,
- parse_qsl,
- namedtuple,
- next,
- reraise,
- raise_from_cause,
- text_type,
- safe_kwarg,
- string_types,
- int_types,
- binary_type,
- nested,
- quote_plus,
- with_metaclass,
- print_,
- itertools_filterfalse,
- u,
- ue,
- b,
- unquote_plus,
- unquote,
- b64decode,
- b64encode,
- byte_buffer,
- itertools_filter,
- iterbytes,
- StringIO,
- inspect_getargspec,
- zip_longest,
-)
-from ._collections import (
- KeyedTuple,
- ImmutableContainer,
- immutabledict,
- Properties,
- OrderedProperties,
- ImmutableProperties,
- OrderedDict,
- OrderedSet,
- IdentitySet,
- OrderedIdentitySet,
- column_set,
- column_dict,
- ordered_column_set,
- populate_column_dict,
- unique_list,
- UniqueAppender,
- PopulateDict,
- EMPTY_SET,
- to_list,
- to_set,
- to_column_set,
- update_copy,
- flatten_iterator,
- has_intersection,
- LRUCache,
- ScopedRegistry,
- ThreadLocalRegistry,
- WeakSequence,
- coerce_generator_arg,
- lightweight_named_tuple,
- collections_abc,
- has_dupes,
-)
+from collections import defaultdict # noqa
+from contextlib import contextmanager # noqa
+from functools import partial # noqa
+from functools import update_wrapper # noqa
-from .langhelpers import (
- iterate_attributes,
- class_hierarchy,
- portable_instancemethod,
- unbound_method_to_callable,
- getargspec_init,
- format_argspec_init,
- format_argspec_plus,
- get_func_kwargs,
- get_cls_kwargs,
- decorator,
- as_interface,
- memoized_property,
- memoized_instancemethod,
- md5_hex,
- group_expirable_memoized_property,
- dependencies,
- decode_slice,
- monkeypatch_proxied_specials,
- asbool,
- bool_or_str,
- coerce_kw_type,
- duck_type_collection,
- assert_arg_type,
- symbol,
- dictlike_iteritems,
- classproperty,
- set_creation_order,
- warn_exception,
- warn,
- NoneType,
- constructor_copy,
- methods_equivalent,
- chop_traceback,
- asint,
- generic_repr,
- counter,
- PluginLoader,
- hybridproperty,
- hybridmethod,
- safe_reraise,
- quoted_token_parser,
- get_callable_argspec,
- only_once,
- attrsetter,
- ellipses_string,
- warn_limited,
- map_bits,
- MemoizedSlots,
- EnsureKWArgType,
- wrap_callable,
-)
+from ._collections import coerce_generator_arg # noqa
+from ._collections import collections_abc # noqa
+from ._collections import column_dict # noqa
+from ._collections import column_set # noqa
+from ._collections import EMPTY_SET # noqa
+from ._collections import flatten_iterator # noqa
+from ._collections import has_dupes # noqa
+from ._collections import has_intersection # noqa
+from ._collections import IdentitySet # noqa
+from ._collections import ImmutableContainer # noqa
+from ._collections import immutabledict # noqa
+from ._collections import ImmutableProperties # noqa
+from ._collections import KeyedTuple # noqa
+from ._collections import lightweight_named_tuple # noqa
+from ._collections import LRUCache # noqa
+from ._collections import ordered_column_set # noqa
+from ._collections import OrderedDict # noqa
+from ._collections import OrderedIdentitySet # noqa
+from ._collections import OrderedProperties # noqa
+from ._collections import OrderedSet # noqa
+from ._collections import populate_column_dict # noqa
+from ._collections import PopulateDict # noqa
+from ._collections import Properties # noqa
+from ._collections import ScopedRegistry # noqa
+from ._collections import ThreadLocalRegistry # noqa
+from ._collections import to_column_set # noqa
+from ._collections import to_list # noqa
+from ._collections import to_set # noqa
+from ._collections import unique_list # noqa
+from ._collections import UniqueAppender # noqa
+from ._collections import update_copy # noqa
+from ._collections import WeakSequence # noqa
+from .compat import b # noqa
+from .compat import b64decode # noqa
+from .compat import b64encode # noqa
+from .compat import binary_type # noqa
+from .compat import byte_buffer # noqa
+from .compat import callable # noqa
+from .compat import cmp # noqa
+from .compat import cpython # noqa
+from .compat import dottedgetter # noqa
+from .compat import inspect_getargspec # noqa
+from .compat import int_types # noqa
+from .compat import iterbytes # noqa
+from .compat import itertools_filter # noqa
+from .compat import itertools_filterfalse # noqa
+from .compat import jython # noqa
+from .compat import namedtuple # noqa
+from .compat import nested # noqa
+from .compat import next # noqa
+from .compat import parse_qsl # noqa
+from .compat import pickle # noqa
+from .compat import print_ # noqa
+from .compat import py2k # noqa
+from .compat import py33 # noqa
+from .compat import py36 # noqa
+from .compat import py3k # noqa
+from .compat import pypy # noqa
+from .compat import quote_plus # noqa
+from .compat import raise_from_cause # noqa
+from .compat import reduce # noqa
+from .compat import reraise # noqa
+from .compat import safe_kwarg # noqa
+from .compat import string_types # noqa
+from .compat import StringIO # noqa
+from .compat import text_type # noqa
+from .compat import threading # noqa
+from .compat import u # noqa
+from .compat import ue # noqa
+from .compat import unquote # noqa
+from .compat import unquote_plus # noqa
+from .compat import win32 # noqa
+from .compat import with_metaclass # noqa
+from .compat import zip_longest # noqa
+from .deprecations import deprecated # noqa
+from .deprecations import inject_docstring_text # noqa
+from .deprecations import pending_deprecation # noqa
+from .deprecations import warn_deprecated # noqa
+from .deprecations import warn_pending_deprecation # noqa
+from .langhelpers import as_interface # noqa
+from .langhelpers import asbool # noqa
+from .langhelpers import asint # noqa
+from .langhelpers import assert_arg_type # noqa
+from .langhelpers import attrsetter # noqa
+from .langhelpers import bool_or_str # noqa
+from .langhelpers import chop_traceback # noqa
+from .langhelpers import class_hierarchy # noqa
+from .langhelpers import classproperty # noqa
+from .langhelpers import coerce_kw_type # noqa
+from .langhelpers import constructor_copy # noqa
+from .langhelpers import counter # noqa
+from .langhelpers import decode_slice # noqa
+from .langhelpers import decorator # noqa
+from .langhelpers import dependencies # noqa
+from .langhelpers import dictlike_iteritems # noqa
+from .langhelpers import duck_type_collection # noqa
+from .langhelpers import ellipses_string # noqa
+from .langhelpers import EnsureKWArgType # noqa
+from .langhelpers import format_argspec_init # noqa
+from .langhelpers import format_argspec_plus # noqa
+from .langhelpers import generic_repr # noqa
+from .langhelpers import get_callable_argspec # noqa
+from .langhelpers import get_cls_kwargs # noqa
+from .langhelpers import get_func_kwargs # noqa
+from .langhelpers import getargspec_init # noqa
+from .langhelpers import group_expirable_memoized_property # noqa
+from .langhelpers import hybridmethod # noqa
+from .langhelpers import hybridproperty # noqa
+from .langhelpers import iterate_attributes # noqa
+from .langhelpers import map_bits # noqa
+from .langhelpers import md5_hex # noqa
+from .langhelpers import memoized_instancemethod # noqa
+from .langhelpers import memoized_property # noqa
+from .langhelpers import MemoizedSlots # noqa
+from .langhelpers import methods_equivalent # noqa
+from .langhelpers import monkeypatch_proxied_specials # noqa
+from .langhelpers import NoneType # noqa
+from .langhelpers import only_once # noqa
+from .langhelpers import PluginLoader # noqa
+from .langhelpers import portable_instancemethod # noqa
+from .langhelpers import quoted_token_parser # noqa
+from .langhelpers import safe_reraise # noqa
+from .langhelpers import set_creation_order # noqa
+from .langhelpers import symbol # noqa
+from .langhelpers import unbound_method_to_callable # noqa
+from .langhelpers import warn # noqa
+from .langhelpers import warn_exception # noqa
+from .langhelpers import warn_limited # noqa
+from .langhelpers import wrap_callable # noqa
-from .deprecations import (
- warn_deprecated,
- warn_pending_deprecation,
- deprecated,
- pending_deprecation,
- inject_docstring_text,
-)
# things that used to be not always available,
# but are now as of current support Python versions
-from collections import defaultdict
-from functools import partial
-from functools import update_wrapper
-from contextlib import contextmanager
diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py
index 67be0e6bf..13575d12d 100644
--- a/lib/sqlalchemy/util/_collections.py
+++ b/lib/sqlalchemy/util/_collections.py
@@ -8,17 +8,17 @@
"""Collection classes and helpers."""
from __future__ import absolute_import
-import weakref
+
import operator
-from .compat import (
- threading,
- itertools_filterfalse,
- string_types,
- binary_types,
- collections_abc,
-)
-from . import py2k
import types
+import weakref
+
+from .compat import binary_types
+from .compat import collections_abc
+from .compat import itertools_filterfalse
+from .compat import py2k
+from .compat import string_types
+from .compat import threading
EMPTY_SET = frozenset()
@@ -196,8 +196,8 @@ class Properties(object):
def __add__(self, other):
return list(self) + list(other)
- def __setitem__(self, key, object):
- self._data[key] = object
+ def __setitem__(self, key, obj):
+ self._data[key] = obj
def __getitem__(self, key):
return self._data[key]
@@ -339,7 +339,7 @@ class OrderedDict(dict):
def iteritems(self):
return iter(self.items())
- def __setitem__(self, key, object):
+ def __setitem__(self, key, obj):
if key not in self:
try:
self._list.append(key)
@@ -347,7 +347,7 @@ class OrderedDict(dict):
# work around Python pickle loads() with
# dict subclass (seems to ignore __setstate__?)
self._list = [key]
- dict.__setitem__(self, key, object)
+ dict.__setitem__(self, key, obj)
def __delitem__(self, key):
dict.__delitem__(self, key)
@@ -822,7 +822,7 @@ def to_list(x, default=None):
def has_intersection(set_, iterable):
- """return True if any items of set_ are present in iterable.
+ r"""return True if any items of set\_ are present in iterable.
Goes through special effort to ensure __hash__ is not called
on items in iterable that don't support it.
diff --git a/lib/sqlalchemy/util/compat.py b/lib/sqlalchemy/util/compat.py
index 553624b49..7963eebb6 100644
--- a/lib/sqlalchemy/util/compat.py
+++ b/lib/sqlalchemy/util/compat.py
@@ -9,10 +9,11 @@
import collections
import contextlib
-import sys
import operator
+import sys
import time
+
py36 = sys.version_info >= (3, 6)
py33 = sys.version_info >= (3, 3)
py35 = sys.version_info >= (3, 5)
@@ -28,7 +29,7 @@ cpython = not pypy and not jython # TODO: something better for this ?
contextmanager = contextlib.contextmanager
dottedgetter = operator.attrgetter
namedtuple = collections.namedtuple
-next = next
+next = next # noqa
ArgSpec = collections.namedtuple(
"ArgSpec", ["args", "varargs", "keywords", "defaults"]
@@ -37,12 +38,12 @@ ArgSpec = collections.namedtuple(
try:
import threading
except ImportError:
- import dummy_threading as threading
+ import dummy_threading as threading # noqa
# work around http://bugs.python.org/issue2646
if py265:
- safe_kwarg = lambda arg: arg
+ safe_kwarg = lambda arg: arg # noqa
else:
safe_kwarg = str
@@ -112,41 +113,44 @@ if py3k:
return s
if py32:
- callable = callable
+ callable = callable # noqa
else:
- def callable(fn):
+ def callable(fn): # noqa
return hasattr(fn, "__call__")
else:
import base64
- import ConfigParser as configparser
+ import ConfigParser as configparser # noqa
import itertools
- from StringIO import StringIO
- from cStringIO import StringIO as byte_buffer
- from inspect import getargspec as inspect_getfullargspec
- from itertools import izip_longest as zip_longest
- from urllib import quote_plus, unquote_plus, quote, unquote
- from urlparse import parse_qsl
+ from StringIO import StringIO # noqa
+ from cStringIO import StringIO as byte_buffer # noqa
+ from inspect import getargspec as inspect_getfullargspec # noqa
+ from itertools import izip_longest as zip_longest # noqa
+ from urllib import quote # noqa
+ from urllib import quote_plus # noqa
+ from urllib import unquote # noqa
+ from urllib import unquote_plus # noqa
+ from urlparse import parse_qsl # noqa
try:
import cPickle as pickle
except ImportError:
- import pickle
+ import pickle # noqa
- string_types = (basestring,)
+ string_types = (basestring,) # noqa
binary_types = (bytes,)
binary_type = str
- text_type = unicode
- int_types = int, long
+ text_type = unicode # noqa
+ int_types = int, long # noqa
inspect_getargspec = inspect_getfullargspec
- callable = callable
- cmp = cmp
- reduce = reduce
+ callable = callable # noqa
+ cmp = cmp # noqa
+ reduce = reduce # noqa
b64encode = base64.b64encode
b64decode = base64.b64decode
@@ -177,7 +181,7 @@ else:
if fp is None:
return
for arg in enumerate(args):
- if not isinstance(arg, basestring):
+ if not isinstance(arg, basestring): # noqa
arg = str(arg)
fp.write(arg)
@@ -186,10 +190,10 @@ else:
# strings - we only use u() with
# literal source strings, and all our source files with non-ascii
# in them (all are tests) are utf-8 encoded.
- return unicode(s, "utf-8")
+ return unicode(s, "utf-8") # noqa
def ue(s):
- return unicode(s, "unicode_escape")
+ return unicode(s, "unicode_escape") # noqa
# not as nice as that of Py3K, but at least preserves
# the code line where the issue occurred
@@ -271,7 +275,7 @@ if py35:
else:
- from inspect import formatargspec as inspect_formatargspec
+ from inspect import formatargspec as inspect_formatargspec # noqa
if win32 or jython:
@@ -284,7 +288,7 @@ else:
if py33:
import collections.abc as collections_abc
else:
- import collections as collections_abc
+ import collections as collections_abc # noqa
@contextlib.contextmanager
@@ -299,22 +303,22 @@ def nested(*managers):
"""
exits = []
- vars = []
+ vars_ = []
exc = (None, None, None)
try:
for mgr in managers:
- exit = mgr.__exit__
+ exit_ = mgr.__exit__
enter = mgr.__enter__
- vars.append(enter())
- exits.append(exit)
- yield vars
+ vars_.append(enter())
+ exits.append(exit_)
+ yield vars_
except:
exc = sys.exc_info()
finally:
while exits:
- exit = exits.pop()
+ exit_ = exits.pop() # noqa
try:
- if exit(*exc):
+ if exit_(*exc):
exc = (None, None, None)
except:
exc = sys.exc_info()
diff --git a/lib/sqlalchemy/util/deprecations.py b/lib/sqlalchemy/util/deprecations.py
index e6612f075..945323530 100644
--- a/lib/sqlalchemy/util/deprecations.py
+++ b/lib/sqlalchemy/util/deprecations.py
@@ -8,10 +8,12 @@
"""Helpers related to deprecation of functions, methods, classes, other
functionality."""
-from .. import exc
-import warnings
import re
+import textwrap
+import warnings
+
from .langhelpers import decorator
+from .. import exc
def warn_deprecated(msg, stacklevel=3):
@@ -127,9 +129,6 @@ def _decorate_with_warning(func, wtype, message, docstring_header=None):
return decorated
-import textwrap
-
-
def _dedent_docstring(text):
split_text = text.split("\n", 1)
if len(split_text) == 1:
diff --git a/lib/sqlalchemy/util/langhelpers.py b/lib/sqlalchemy/util/langhelpers.py
index 6a286998b..49b5eb87f 100644
--- a/lib/sqlalchemy/util/langhelpers.py
+++ b/lib/sqlalchemy/util/langhelpers.py
@@ -9,6 +9,8 @@
modules, classes, hierarchies, attributes, functions, and methods.
"""
+from functools import update_wrapper
+import hashlib
import inspect
import itertools
import operator
@@ -16,11 +18,10 @@ import re
import sys
import types
import warnings
-from functools import update_wrapper
-from .. import exc
-import hashlib
-from . import compat
+
from . import _collections
+from . import compat
+from .. import exc
def md5_hex(x):
@@ -857,7 +858,10 @@ def memoized_instancemethod(fn):
def oneshot(self, *args, **kw):
result = fn(self, *args, **kw)
- memo = lambda *a, **kw: result
+
+ def memo(*a, **kw):
+ return result
+
memo.__name__ = fn.__name__
memo.__doc__ = fn.__doc__
self.__dict__[fn.__name__] = memo
@@ -914,7 +918,10 @@ class MemoizedSlots(object):
def oneshot(*args, **kw):
result = fn(*args, **kw)
- memo = lambda *a, **kw: result
+
+ def memo(*a, **kw):
+ return result
+
memo.__name__ = fn.__name__
memo.__doc__ = fn.__doc__
setattr(self, key, memo)
@@ -928,8 +935,6 @@ class MemoizedSlots(object):
def dependency_for(modulename, add_to_all=False):
def decorate(obj):
- # TODO: would be nice to improve on this import silliness,
- # unfortunately importlib doesn't work that great either
tokens = modulename.split(".")
mod = compat.import_(
".".join(tokens[0:-1]), globals(), locals(), [tokens[-1]]
@@ -1461,7 +1466,7 @@ def attrsetter(attrname):
class EnsureKWArgType(type):
- """Apply translation of functions to accept **kw arguments if they
+ r"""Apply translation of functions to accept \**kw arguments if they
don't already.
"""
diff --git a/lib/sqlalchemy/util/queue.py b/lib/sqlalchemy/util/queue.py
index 5e56e855a..bb5df99e9 100644
--- a/lib/sqlalchemy/util/queue.py
+++ b/lib/sqlalchemy/util/queue.py
@@ -20,6 +20,7 @@ condition.
from collections import deque
from time import time as _time
+
from .compat import threading
diff --git a/lib/sqlalchemy/util/topological.py b/lib/sqlalchemy/util/topological.py
index 95391c31b..3cc5ef04f 100644
--- a/lib/sqlalchemy/util/topological.py
+++ b/lib/sqlalchemy/util/topological.py
@@ -7,8 +7,9 @@
"""Topological sorting algorithms."""
-from ..exc import CircularDependencyError
from .. import util
+from ..exc import CircularDependencyError
+
__all__ = ["sort", "sort_as_subsets", "find_cycles"]