diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-08 17:14:41 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-13 15:29:20 -0400 |
commit | 769fa67d842035dd852ab8b6a26ea3f110a51131 (patch) | |
tree | 5c121caca336071091c6f5ea4c54743c92d6458a /lib/sqlalchemy/sql/selectable.py | |
parent | 77fc8216a74e6b2d0efc6591c6c735687bd10002 (diff) | |
download | sqlalchemy-769fa67d842035dd852ab8b6a26ea3f110a51131.tar.gz |
pep-484: sqlalchemy.sql pass one
sqlalchemy.sql will require many passes to get all
modules even gradually typed. Will have to pick and
choose what modules can be strictly typed vs. which
can be gradual.
in this patch, emphasis is on visitors.py, cache_key.py,
annotations.py for strict typing, compiler.py is on gradual
typing but has much more structure, in particular where it
connects with the outside world.
The work within compiler.py also reached back out to
engine/cursor.py , default.py quite a bit.
References: #6810
Change-Id: I6e8a29f6013fd216e43d45091bc193f8be0368fd
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
-rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index e5c2bef68..09befb078 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -53,7 +53,6 @@ from .base import Generative from .base import HasCompileState from .base import HasMemoized from .base import Immutable -from .base import prefix_anon_map from .coercions import _document_text_coercion from .elements import _anonymous_label from .elements import BindParameter @@ -69,10 +68,10 @@ from .elements import literal_column from .elements import TableValuedColumn from .elements import UnaryExpression from .visitors import InternalTraversal +from .visitors import prefix_anon_map from .. import exc from .. import util - and_ = BooleanClauseList.and_ _T = TypeVar("_T", bound=Any) @@ -855,6 +854,12 @@ class FromClause(roles.AnonymizedFromClauseRole, Selectable): return self.alias(name=name) +class NamedFromClause(FromClause): + named_with_column = True + + name: str + + class SelectLabelStyle(Enum): """Label style constants that may be passed to :meth:`_sql.Select.set_label_style`.""" @@ -1317,15 +1322,16 @@ class NoInit: # -> Lateral -> FromClause, but we accept SelectBase # w/ non-deprecated coercion # -> TableSample -> only for FromClause -class AliasedReturnsRows(NoInit, FromClause): +class AliasedReturnsRows(NoInit, NamedFromClause): """Base class of aliases against tables, subqueries, and other selectables.""" _is_from_container = True - named_with_column = True _supports_derived_columns = False + element: ClauseElement + _traverse_internals = [ ("element", InternalTraversal.dp_clauseelement), ("name", InternalTraversal.dp_anon_name), @@ -1423,6 +1429,8 @@ class Alias(roles.DMLTableRole, AliasedReturnsRows): inherit_cache = True + element: FromClause + @classmethod def _factory(cls, selectable, name=None, flat=False): return coercions.expect( @@ -1689,6 +1697,8 @@ class CTE( + HasSuffixes._has_suffixes_traverse_internals ) + element: HasCTE + @classmethod def _factory(cls, selectable, name=None, recursive=False): r"""Return a new :class:`_expression.CTE`, @@ -1819,7 +1829,7 @@ class _CTEOpts(NamedTuple): nesting: bool -class HasCTE(roles.HasCTERole): +class HasCTE(roles.HasCTERole, ClauseElement): """Mixin that declares a class to include CTE support. .. versionadded:: 1.1 @@ -2247,6 +2257,8 @@ class Subquery(AliasedReturnsRows): inherit_cache = True + element: Select + @classmethod def _factory(cls, selectable, name=None): """Return a :class:`.Subquery` object.""" @@ -2331,7 +2343,7 @@ class FromGrouping(GroupedElement, FromClause): self.element = state["element"] -class TableClause(roles.DMLTableRole, Immutable, FromClause): +class TableClause(roles.DMLTableRole, Immutable, NamedFromClause): """Represents a minimal "table" construct. This is a lightweight table object that has only a name, a @@ -2371,8 +2383,6 @@ class TableClause(roles.DMLTableRole, Immutable, FromClause): ("name", InternalTraversal.dp_string), ] - named_with_column = True - _is_table = True implicit_returning = False @@ -2542,7 +2552,7 @@ class ForUpdateArg(ClauseElement): SelfValues = typing.TypeVar("SelfValues", bound="Values") -class Values(Generative, FromClause): +class Values(Generative, NamedFromClause): """Represent a ``VALUES`` construct that can be used as a FROM element in a statement. @@ -2553,7 +2563,6 @@ class Values(Generative, FromClause): """ - named_with_column = True __visit_name__ = "values" _data = () |