diff options
| -rw-r--r-- | doc/build/changelog/unreleased_20/9156.rst | 7 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/elements.py | 2 | ||||
| -rw-r--r-- | test/ext/mypy/plugin_files/issue_9156.py | 11 |
3 files changed, 19 insertions, 1 deletions
diff --git a/doc/build/changelog/unreleased_20/9156.rst b/doc/build/changelog/unreleased_20/9156.rst new file mode 100644 index 000000000..9fbeb44eb --- /dev/null +++ b/doc/build/changelog/unreleased_20/9156.rst @@ -0,0 +1,7 @@ +.. change:: + :tags: bug, typing + :tickets: 9156 + + The :meth:`_expression.ColumnElement.cast` is typed to accept + both ``Type[TypeEngine[T]]`` and ``TypeEngine[T]`` rather only + ``TypeEngine[T]``.
\ No newline at end of file diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index 71d8cb2d3..c3f7b884c 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -1641,7 +1641,7 @@ class ColumnElement( co._is_clone_of = selectable._is_clone_of.columns.get(key) return key, co - def cast(self, type_: TypeEngine[_T]) -> Cast[_T]: + def cast(self, type_: _TypeEngineArgument[_T]) -> Cast[_T]: """Produce a type cast, i.e. ``CAST(<expression> AS <type>)``. This is a shortcut to the :func:`_expression.cast` function. diff --git a/test/ext/mypy/plugin_files/issue_9156.py b/test/ext/mypy/plugin_files/issue_9156.py new file mode 100644 index 000000000..46e5e9570 --- /dev/null +++ b/test/ext/mypy/plugin_files/issue_9156.py @@ -0,0 +1,11 @@ +from typing import Any, Type + +from sqlalchemy.sql.elements import ColumnElement +from sqlalchemy.sql.type_api import TypeEngine + +col: ColumnElement[Any] +type_: Type[TypeEngine[Any]] +obj: TypeEngine[Any] + +col.cast(type_) +col.cast(obj) |
