From: Federico Caselli Date: Tue, 12 Sep 2023 20:08:25 +0000 (+0200) Subject: Fix Existing.select_from type definition X-Git-Tag: rel_2_0_21~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb4fb3d477a968115716fdff4ce837cdde357353;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix Existing.select_from type definition Fixed typing issue with :meth:`_sql.Existing.select_from` that prevented its use with ORM classes. Fixes: #10337 Change-Id: I4324c09054803f0b1ae7c4bde202cad0b55e1a4f --- diff --git a/doc/build/changelog/unreleased_20/10337.rst b/doc/build/changelog/unreleased_20/10337.rst new file mode 100644 index 0000000000..26020d74fc --- /dev/null +++ b/doc/build/changelog/unreleased_20/10337.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, typing + :tickets: 10337 + + Fixed typing issue with :meth:`_sql.Existing.select_from` that + prevented its use with ORM classes. diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 71fca7e1f2..b4061a80e6 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -6728,7 +6728,7 @@ class Exists(UnaryExpression[bool]): ) return e - def select_from(self, *froms: FromClause) -> Self: + def select_from(self, *froms: _FromClauseArgument) -> Self: """Return a new :class:`_expression.Exists` construct, applying the given expression to the :meth:`_expression.Select.select_from` diff --git a/test/typing/plain_files/orm/typed_queries.py b/test/typing/plain_files/orm/typed_queries.py index 530e5f670f..722729b506 100644 --- a/test/typing/plain_files/orm/typed_queries.py +++ b/test/typing/plain_files/orm/typed_queries.py @@ -6,6 +6,7 @@ from sqlalchemy import Column from sqlalchemy import column from sqlalchemy import create_engine from sqlalchemy import delete +from sqlalchemy import exists from sqlalchemy import func from sqlalchemy import insert from sqlalchemy import Integer @@ -530,3 +531,8 @@ def t_aliased_fromclause() -> None: # EXPECTED_TYPE: FromClause reveal_type(a4) + + +def test_select_from() -> None: + select(1).select_from(User).exists() + exists(1).select_from(User).select()