diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-01 11:07:25 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-02 10:47:03 -0500 |
commit | 45f7b3b8ac9a1b393b45f2f199a88c3bb0c86705 (patch) | |
tree | 5686c12e8030cfe423c181d9a9f9cf1caaed2489 /lib/sqlalchemy/sql/selectable.py | |
parent | 466c3fde848e28cc85f2a78dd9a76f85455479f8 (diff) | |
download | sqlalchemy-45f7b3b8ac9a1b393b45f2f199a88c3bb0c86705.tar.gz |
TextualSelect is ReturnsRowsRole
Fixed typing bug where :meth:`_sql.Select.from_statement` would not accept
:func:`_sql.text` or :class:`.TextualSelect` objects as a valid type.
Additionally repaired the :class:`.TextClause.columns` method to have a
return type, which was missing.
Fixes: #9398
Change-Id: I627fc33bf83365e1c7f7c6ed29ea387dfd4a57d8
Diffstat (limited to 'lib/sqlalchemy/sql/selectable.py')
-rw-r--r-- | lib/sqlalchemy/sql/selectable.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index 75b5d09e3..39ef420dd 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -4551,7 +4551,7 @@ class SelectState(util.MemoizedSlots, CompileState): @classmethod def from_statement( - cls, statement: Select[Any], from_statement: ExecutableReturnsRows + cls, statement: Select[Any], from_statement: roles.ReturnsRowsRole ) -> ExecutableReturnsRows: cls._plugin_not_implemented() @@ -5273,7 +5273,7 @@ class Select( return meth(self) def from_statement( - self, statement: ExecutableReturnsRows + self, statement: roles.ReturnsRowsRole ) -> ExecutableReturnsRows: """Apply the columns which this :class:`.Select` would select onto another statement. @@ -6770,7 +6770,7 @@ class Exists(UnaryExpression[bool]): return e -class TextualSelect(SelectBase, Executable, Generative): +class TextualSelect(SelectBase, ExecutableReturnsRows, Generative): """Wrap a :class:`_expression.TextClause` construct within a :class:`_expression.SelectBase` interface. @@ -6815,14 +6815,28 @@ class TextualSelect(SelectBase, Executable, Generative): def __init__( self, text: TextClause, - columns: List[ColumnClause[Any]], + columns: List[_ColumnExpressionArgument[Any]], + positional: bool = False, + ) -> None: + + self._init( + text, + # convert for ORM attributes->columns, etc + [ + coercions.expect(roles.LabeledColumnExprRole, c) + for c in columns + ], + positional, + ) + + def _init( + self, + text: TextClause, + columns: List[NamedColumn[Any]], positional: bool = False, ) -> None: self.element = text - # convert for ORM attributes->columns, etc - self.column_args = [ - coercions.expect(roles.ColumnsClauseRole, c) for c in columns - ] + self.column_args = columns self.positional = positional @HasMemoized_ro_memoized_attribute |