diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-04-15 11:05:36 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-04-20 15:14:09 -0400 |
commit | aeeff72e806420bf85e2e6723b1f941df38a3e1a (patch) | |
tree | 0bed521b4d7c4860f998e51ba5e318d18b2f5900 /lib/sqlalchemy/sql/_typing.py | |
parent | 13a8552053c21a9fa7ff6f992ed49ee92cca73e4 (diff) | |
download | sqlalchemy-aeeff72e806420bf85e2e6723b1f941df38a3e1a.tar.gz |
pep-484: ORM public API, constructors
for the moment, abandoning using @overload with
relationship() and mapped_column(). The overloads
are very difficult to get working at all, and
the overloads that were there all wouldn't pass on
mypy. various techniques of getting them to
"work", meaning having right hand side dictate
what's legal on the left, have mixed success
and wont give consistent results; additionally,
it's legal to have Optional / non-optional
independent of nullable in any case for columns.
relationship cases are less ambiguous but mypy
was not going along with things.
we have a comprehensive system of allowing
left side annotations to drive the right side,
in the absense of explicit settings on the right.
so type-centric SQLAlchemy will be left-side
driven just like dataclasses, and the various flags
and switches on the right side will just not be
needed very much.
in other matters, one surprise, forgot to remove string support
from orm.join(A, B, "somename") or do deprecations
for it in 1.4. This is a really not-directly-used
structure barely
mentioned in the docs for many years, the example
shows a relationship being used, not a string, so
we will just change it to raise the usual error here.
Change-Id: Iefbbb8d34548b538023890ab8b7c9a5d9496ec6e
Diffstat (limited to 'lib/sqlalchemy/sql/_typing.py')
-rw-r--r-- | lib/sqlalchemy/sql/_typing.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/sqlalchemy/sql/_typing.py b/lib/sqlalchemy/sql/_typing.py index b0a717a1a..53d29b628 100644 --- a/lib/sqlalchemy/sql/_typing.py +++ b/lib/sqlalchemy/sql/_typing.py @@ -2,13 +2,14 @@ from __future__ import annotations import operator from typing import Any +from typing import Callable from typing import Dict +from typing import Set from typing import Type from typing import TYPE_CHECKING from typing import TypeVar from typing import Union -from sqlalchemy.sql.base import Executable from . import roles from .. import util from ..inspection import Inspectable @@ -16,6 +17,7 @@ from ..util.typing import Literal from ..util.typing import Protocol if TYPE_CHECKING: + from .base import Executable from .compiler import Compiled from .compiler import DDLCompiler from .compiler import SQLCompiler @@ -27,17 +29,20 @@ if TYPE_CHECKING: from .elements import quoted_name from .elements import SQLCoreOperations from .elements import TextClause + from .lambdas import LambdaElement from .roles import ColumnsClauseRole from .roles import FromClauseRole from .schema import Column from .schema import DefaultGenerator from .schema import Sequence + from .schema import Table from .selectable import Alias from .selectable import FromClause from .selectable import Join from .selectable import NamedFromClause from .selectable import ReturnsRows from .selectable import Select + from .selectable import Selectable from .selectable import SelectBase from .selectable import Subquery from .selectable import TableClause @@ -46,7 +51,6 @@ if TYPE_CHECKING: from .type_api import TypeEngine from ..util.typing import TypeGuard - _T = TypeVar("_T", bound=Any) @@ -89,7 +93,11 @@ sets; select(...), insert().returning(...), etc. """ _ColumnExpressionArgument = Union[ - "ColumnElement[_T]", _HasClauseElement, roles.ExpressionElementRole[_T] + "ColumnElement[_T]", + _HasClauseElement, + roles.ExpressionElementRole[_T], + Callable[[], "ColumnElement[_T]"], + "LambdaElement", ] """narrower "column expression" argument. @@ -103,6 +111,7 @@ overall which brings in the TextClause object also. """ + _InfoType = Dict[Any, Any] """the .info dictionary accepted and used throughout Core /ORM""" @@ -169,6 +178,8 @@ _PropagateAttrsType = util.immutabledict[str, Any] _TypeEngineArgument = Union[Type["TypeEngine[_T]"], "TypeEngine[_T]"] +_EquivalentColumnMap = Dict["ColumnElement[Any]", Set["ColumnElement[Any]"]] + if TYPE_CHECKING: def is_sql_compiler(c: Compiled) -> TypeGuard[SQLCompiler]: @@ -195,6 +206,9 @@ if TYPE_CHECKING: def is_table_value_type(t: TypeEngine[Any]) -> TypeGuard[TableValueType]: ... + def is_selectable(t: Any) -> TypeGuard[Selectable]: + ... + def is_select_base( t: Union[Executable, ReturnsRows] ) -> TypeGuard[SelectBase]: @@ -224,6 +238,7 @@ else: is_from_clause = operator.attrgetter("_is_from_clause") is_tuple_type = operator.attrgetter("_is_tuple_type") is_table_value_type = operator.attrgetter("_is_table_value") + is_selectable = operator.attrgetter("is_selectable") is_select_base = operator.attrgetter("_is_select_base") is_select_statement = operator.attrgetter("_is_select_statement") is_table = operator.attrgetter("_is_table") |