diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-02-28 11:05:48 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-02-28 11:50:54 -0500 |
| commit | da70478eb2eafe9c76b836217371e029c3c820e3 (patch) | |
| tree | 96f7310c68fd659ab472832e45107095c70081f6 /lib | |
| parent | a7f3dad6c93ab43a11521a2ecd240b5e023367fc (diff) | |
| download | sqlalchemy-da70478eb2eafe9c76b836217371e029c3c820e3.tar.gz | |
ensure single import per line
This adds the very small plugin flake8-import-single which
will prevent us from having an import with more than one symbol
on a line.
Flake8 by itself prevents this pattern with E401:
import collections, os, sys
However does not do anything with this:
from sqlalchemy import Column, text
Both statements have the same issues generating merge artifacts
as well as presenting a manual decision to be made. While
zimports generally cleans up such imports at the top level, we
don't enforce zimports / pre-commit use.
the plugin finds the same issue for imports that are inside of
test methods. We shouldn't usually have imports in test methods
so most of them here are moved to be top level.
The version is pinned at 0.1.5; the project seems to have no
activity since 2019, however there are three 0.1.6dev releases
on pypi which stopped in September 2019, they seem to be
experiments with packaging. The source for 0.1.5
is extremely simple and only reveals one method to flake8
(the run() method).
Change-Id: Icea894e43bad9c0b5d4feb5f49c6c666d6ea6aa1
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/clsregistry.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/loading.py | 6 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/fixtures.py | 8 |
3 files changed, 9 insertions, 8 deletions
diff --git a/lib/sqlalchemy/orm/clsregistry.py b/lib/sqlalchemy/orm/clsregistry.py index e5fff4a5e..c4d6c29eb 100644 --- a/lib/sqlalchemy/orm/clsregistry.py +++ b/lib/sqlalchemy/orm/clsregistry.py @@ -553,7 +553,8 @@ def _resolver( if _fallback_dict is None: import sqlalchemy - from sqlalchemy.orm import foreign, remote + from . import foreign + from . import remote _fallback_dict = util.immutabledict(sqlalchemy.__dict__).union( {"foreign": foreign, "remote": remote} diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py index 7974d94c5..3d9ff7b0a 100644 --- a/lib/sqlalchemy/orm/loading.py +++ b/lib/sqlalchemy/orm/loading.py @@ -37,6 +37,8 @@ from .base import _RAISE_FOR_STATE from .base import _SET_DEFERRED_EXPIRED from .base import PassiveFlag from .context import FromStatement +from .context import ORMCompileState +from .context import QueryContext from .util import _none_set from .util import state_str from .. import exc as sa_exc @@ -55,7 +57,6 @@ from ..util import EMPTY_DICT if TYPE_CHECKING: from ._typing import _IdentityKeyType from .base import LoaderCallableStatus - from .context import QueryContext from .interfaces import ORMOption from .mapper import Mapper from .query import Query @@ -519,9 +520,6 @@ def load_on_pk_identity( assert not q._is_lambda_element - # TODO: fix these imports .... - from .context import QueryContext, ORMCompileState - if load_options is None: load_options = QueryContext.default_load_options diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py index 3b58052b8..a8bc6c50a 100644 --- a/lib/sqlalchemy/testing/fixtures.py +++ b/lib/sqlalchemy/testing/fixtures.py @@ -24,7 +24,12 @@ from .entities import ComparableEntity from .entities import ComparableMixin # noqa from .util import adict from .util import drop_all_tables_from_metadata +from .. import Column from .. import event +from .. import func +from .. import Integer +from .. import select +from .. import Table from .. import util from ..orm import DeclarativeBase from ..orm import events as orm_events @@ -247,9 +252,6 @@ class TestBase: def trans_ctx_manager_fixture(self, request, metadata): rollback, second_operation, begin_nested = request.param - from sqlalchemy import Table, Column, Integer, func, select - from . import eq_ - t = Table("test", metadata, Column("data", Integer)) eng = getattr(self, "bind", None) or config.db |
