summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-03-10 11:57:00 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-03-12 11:42:50 -0500
commit4c28867f944637ef313f98d5f09da05255418c6d (patch)
treef68776450fc91df8085446d517020603b879d0f8 /lib/sqlalchemy/sql
parent03989d1dce80999bb9ea1a7d36df3285e5ce4c3b (diff)
downloadsqlalchemy-4c28867f944637ef313f98d5f09da05255418c6d.tar.gz
additional mypy strictness
enable type checking within untyped defs. This allowed some more internals to be fixed up with assertions etc. some internals that were unnecessary or not even used at all were removed. BaseCursorResult was no longer necessary since we only have one kind of CursorResult now. The different ResultProxy subclasses that had alternate "strategies" dont appear to be used at all even in 1.4.x, as there's no code that accesses the _cursor_strategy_cls attribute, which is also removed. As these were mostly private constructs that weren't even functioning correctly in any case, it's fine to remove these over the 2.0 boundary. Change-Id: Ifd536987d104b1cd8b546cefdbd5c1e5d1801082
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/compiler.py9
-rw-r--r--lib/sqlalchemy/sql/elements.py32
-rw-r--r--lib/sqlalchemy/sql/schema.py1
-rw-r--r--lib/sqlalchemy/sql/selectable.py3
4 files changed, 33 insertions, 12 deletions
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 09e38a5ab..423c3d446 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -34,6 +34,7 @@ import re
from time import perf_counter
import typing
from typing import Any
+from typing import Callable
from typing import Dict
from typing import List
from typing import Mapping
@@ -629,11 +630,11 @@ class SQLCompiler(Compiled):
"""list of columns that can be post-fetched after INSERT or UPDATE to
receive server-updated values"""
- insert_prefetch: Optional[List[Column[Any]]]
+ insert_prefetch: Sequence[Column[Any]] = ()
"""list of columns for which default values should be evaluated before
an INSERT takes place"""
- update_prefetch: Optional[List[Column[Any]]]
+ update_prefetch: Sequence[Column[Any]] = ()
"""list of columns for which onupdate default values should be evaluated
before an UPDATE takes place"""
@@ -739,8 +740,6 @@ class SQLCompiler(Compiled):
"""if True, there are bindparam() objects that have the isoutparam
flag set."""
- insert_prefetch = update_prefetch = ()
-
postfetch_lastrowid = False
"""if True, and this in insert, use cursor.lastrowid to populate
result.inserted_primary_key. """
@@ -1340,7 +1339,7 @@ class SQLCompiler(Compiled):
)
@util.memoized_property
- def _within_exec_param_key_getter(self):
+ def _within_exec_param_key_getter(self) -> Callable[[Any], str]:
getter = self._key_getters_for_crud_column[2]
if self.escaped_bind_names:
diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py
index 4c38c4efa..168da17cc 100644
--- a/lib/sqlalchemy/sql/elements.py
+++ b/lib/sqlalchemy/sql/elements.py
@@ -58,12 +58,13 @@ from ..util.langhelpers import TypingOnly
if typing.TYPE_CHECKING:
from decimal import Decimal
+ from .compiler import Compiled
+ from .compiler import SQLCompiler
from .operators import OperatorType
from .selectable import FromClause
from .selectable import Select
from .sqltypes import Boolean # noqa
from .type_api import TypeEngine
- from ..engine import Compiled
from ..engine import Connection
from ..engine import Dialect
from ..engine import Engine
@@ -573,6 +574,25 @@ class ClauseElement(
)
+class DQLDMLClauseElement(ClauseElement):
+ """represents a :class:`.ClauseElement` that compiles to a DQL or DML
+ expression, not DDL.
+
+ .. versionadded:: 2.0
+
+ """
+
+ if typing.TYPE_CHECKING:
+
+ def compile( # noqa: A001
+ self,
+ bind: Optional[Union[Engine, Connection]] = None,
+ dialect: Optional[Dialect] = None,
+ **kw: Any,
+ ) -> SQLCompiler:
+ ...
+
+
class CompilerColumnElement(
roles.DMLColumnRole,
roles.DDLConstraintColumnRole,
@@ -955,7 +975,7 @@ class ColumnElement(
roles.DDLExpressionRole,
SQLCoreOperations[_T],
operators.ColumnOperators[SQLCoreOperations],
- ClauseElement,
+ DQLDMLClauseElement,
):
"""Represent a column-oriented SQL expression suitable for usage in the
"columns" clause, WHERE clause etc. of a statement.
@@ -1820,7 +1840,7 @@ class BindParameter(roles.InElementRole, ColumnElement[_T]):
)
-class TypeClause(ClauseElement):
+class TypeClause(DQLDMLClauseElement):
"""Handle a type keyword in a SQL statement.
Used by the ``Case`` statement.
@@ -1849,7 +1869,7 @@ class TextClause(
roles.BinaryElementRole,
roles.InElementRole,
Executable,
- ClauseElement,
+ DQLDMLClauseElement,
):
"""Represent a literal SQL text fragment.
@@ -2285,7 +2305,7 @@ class ClauseList(
roles.OrderByRole,
roles.ColumnsClauseRole,
roles.DMLColumnRole,
- ClauseElement,
+ DQLDMLClauseElement,
):
"""Describe a list of clauses, separated by an operator.
@@ -3205,7 +3225,7 @@ class IndexExpression(BinaryExpression):
inherit_cache = True
-class GroupedElement(ClauseElement):
+class GroupedElement(DQLDMLClauseElement):
"""Represent any parenthesized expression"""
__visit_name__ = "grouping"
diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index fdae4d7b0..c270e1564 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -1131,6 +1131,7 @@ class Column(DialectKWArgs, SchemaItem, ColumnClause[_T]):
__visit_name__ = "column"
inherit_cache = True
+ key: str
@overload
def __init__(
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py
index a5cbffb5e..e5c2bef68 100644
--- a/lib/sqlalchemy/sql/selectable.py
+++ b/lib/sqlalchemy/sql/selectable.py
@@ -62,6 +62,7 @@ from .elements import ClauseElement
from .elements import ClauseList
from .elements import ColumnClause
from .elements import ColumnElement
+from .elements import DQLDMLClauseElement
from .elements import GroupedElement
from .elements import Grouping
from .elements import literal_column
@@ -85,7 +86,7 @@ class _OffsetLimitParam(BindParameter):
return self.effective_value
-class ReturnsRows(roles.ReturnsRowsRole, ClauseElement):
+class ReturnsRows(roles.ReturnsRowsRole, DQLDMLClauseElement):
"""The base-most class for Core constructs that have some concept of
columns that can represent rows.