summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-01-01 18:24:03 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-01-04 12:56:26 -0500
commit217948f5c79e03956de998af86fef77ebc3edb76 (patch)
tree761aaf7ae0a379863e6f149c6812d0d3794ba10a /lib/sqlalchemy/sql
parent5881fd274015af3de37f2ff0f91ff6a7c61c1540 (diff)
downloadsqlalchemy-217948f5c79e03956de998af86fef77ebc3edb76.tar.gz
Enable F821
In Ia63a510f9c1d08b055eef62cf047f1f427f0450c we introduced "lambda combinations" which use a bit of function closure inspection in order to allow for testing combinations that make use of symbols that come from test fixtures, or from the test itself. Two problems. One is that we can't use F821 flake8 rule without either adding lots of noqas, skipping the file, or adding arguments to the lambdas themselves that are then populated, which makes for a very verbose system. The other is that the system is already verbose with all those lambdas and the magic in use is a non-explicit kind, hence F821 reminds us that if we can improve upon this, we should. So let's improve upon it by making it so that the "lambda" is just once and up front for the whole thing, and let it accept the arguments directly. This still requires magic, because these test cases need to resolve at test collection time, not test runtime. But we will instead substitute a namespace up front that can be coerced into its desired form within the tests. Additionally, there's a little bit of py2k compatible type annotations present; f821 is checking these, so we have to add those imports also using the TYPE_CHECKING boolean so they don't take place in py2k. Change-Id: Idb7e7a0c8af86d9ab133f548511306ef68cdba14
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/base.py9
-rw-r--r--lib/sqlalchemy/sql/coercions.py11
-rw-r--r--lib/sqlalchemy/sql/elements.py7
-rw-r--r--lib/sqlalchemy/sql/selectable.py8
4 files changed, 25 insertions, 10 deletions
diff --git a/lib/sqlalchemy/sql/base.py b/lib/sqlalchemy/sql/base.py
index 60456223f..a7324c45f 100644
--- a/lib/sqlalchemy/sql/base.py
+++ b/lib/sqlalchemy/sql/base.py
@@ -19,9 +19,12 @@ from .visitors import ClauseVisitor
from .. import exc
from .. import util
-coercions = None # type: types.ModuleType
-elements = None # type: types.ModuleType
-type_api = None # type: types.ModuleType
+if util.TYPE_CHECKING:
+ from types import ModuleType
+
+coercions = None # type: ModuleType
+elements = None # type: ModuleType
+type_api = None # type: ModuleType
PARSE_AUTOCOMMIT = util.symbol("PARSE_AUTOCOMMIT")
NO_ARG = util.symbol("NO_ARG")
diff --git a/lib/sqlalchemy/sql/coercions.py b/lib/sqlalchemy/sql/coercions.py
index 12ec7c750..b3bf4e93b 100644
--- a/lib/sqlalchemy/sql/coercions.py
+++ b/lib/sqlalchemy/sql/coercions.py
@@ -17,10 +17,13 @@ from .. import inspection
from .. import util
from ..util import collections_abc
-elements = None # type: types.ModuleType
-schema = None # type: types.ModuleType
-selectable = None # type: types.ModuleType
-sqltypes = None # type: types.ModuleType
+if util.TYPE_CHECKING:
+ from types import ModuleType
+
+elements = None # type: ModuleType
+schema = None # type: ModuleType
+selectable = None # type: ModuleType
+sqltypes = None # type: ModuleType
def _is_literal(element):
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index d94d91b16..422eb6220 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -43,6 +43,11 @@ from .. import exc
from .. import inspection
from .. import util
+if util.TYPE_CHECKING:
+ from typing import Any
+ from typing import Optional
+ from typing import Union
+
def collate(expression, collation):
"""Return the clause ``expression COLLATE collation``.
@@ -709,7 +714,7 @@ class ColumnElement(
_alt_names = ()
def self_group(self, against=None):
- # type: (Module, Module, Optional[Any]) -> ClauseEleent
+ # type: (Optional[Any]) -> ClauseElement
if (
against in (operators.and_, operators.or_, operators._asbool)
and self.type._type_affinity is type_api.BOOLEANTYPE._type_affinity
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index 8f5503db0..136c9f868 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -50,6 +50,10 @@ from .visitors import InternalTraversal
from .. import exc
from .. import util
+if util.TYPE_CHECKING:
+ from typing import Any
+ from typing import Optional
+
class _OffsetLimitParam(BindParameter):
@property
@@ -2096,7 +2100,7 @@ class SelectBase(
_memoized_property = util.group_expirable_memoized_property()
def _generate_fromclause_column_proxies(self, fromclause):
- # type: (FromClause)
+ # type: (FromClause) -> None
raise NotImplementedError()
def _refresh_for_new_column(self, column):
@@ -2344,7 +2348,7 @@ class SelectStatementGrouping(GroupedElement, SelectBase):
_is_select_container = True
def __init__(self, element):
- # type: (SelectBase)
+ # type: (SelectBase) -> None
self.element = coercions.expect(roles.SelectStatementRole, element)
@property