From ceb9e021cd5df3aa7f3beed2c9564d5f182bf8b6 Mon Sep 17 00:00:00 2001 From: wouter bolsterlee Date: Thu, 4 Apr 2024 14:15:07 -0400 Subject: [PATCH] typing: annotate Exists.select() to return Select[bool] MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: #11231 A query of the form: ``` sql SELECT EXISTS ( SELECT 1 FROM ... WHERE ... ) ``` … returns a boolean. Closes: #11233 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/11233 Pull-request-sha: 1bec1cac731eb42e097948f84ae3d0ef133f8a9a Change-Id: I407a3bd9ed21a180c6c3ff02250aa0a9fbe502d7 --- lib/sqlalchemy/sql/selectable.py | 2 +- test/typing/plain_files/sql/common_sql_element.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 4ae60b7724..c28d4df0e4 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -6674,7 +6674,7 @@ class Exists(UnaryExpression[bool]): assert isinstance(return_value, SelectStatementGrouping) return return_value - def select(self) -> Select[Unpack[TupleAny]]: + def select(self) -> Select[bool]: r"""Return a SELECT of this :class:`_expression.Exists`. e.g.:: diff --git a/test/typing/plain_files/sql/common_sql_element.py b/test/typing/plain_files/sql/common_sql_element.py index 89c0c4d2ef..7c8001a728 100644 --- a/test/typing/plain_files/sql/common_sql_element.py +++ b/test/typing/plain_files/sql/common_sql_element.py @@ -98,6 +98,11 @@ stmt2 = ( # EXPECTED_TYPE: Select[int] reveal_type(stmt2) +stmt3 = select(User.id).exists().select() + +# EXPECTED_TYPE: Select[bool] +reveal_type(stmt3) + receives_str_col_expr(User.email) receives_str_col_expr(User.email + "some expr") -- 2.47.2