--- /dev/null
+.. change::
+ :tags: bug, typing
+ :tickets: 9451
+
+ Fixed typing issue where :meth:`.ColumnElement.cast` did not allow a
+ :class:`.TypeEngine` argument independent of the type of the
+ :class:`.ColumnElement` itself, which is the purpose of
+ :meth:`.ColumnElement.cast`.
co._is_clone_of = selectable._is_clone_of.columns.get(key)
return key, co
- def cast(self, type_: _TypeEngineArgument[_T]) -> Cast[_T]:
+ def cast(self, type_: _TypeEngineArgument[_OPT]) -> Cast[_OPT]:
"""Produce a type cast, i.e. ``CAST(<expression> AS <type>)``.
This is a shortcut to the :func:`_expression.cast` function.
from sqlalchemy import and_
from sqlalchemy import Boolean
+from sqlalchemy import cast
from sqlalchemy import column
+from sqlalchemy import DateTime
from sqlalchemy import false
+from sqlalchemy import Float
from sqlalchemy import func
from sqlalchemy import Integer
from sqlalchemy import or_
and_(c1.not_ilike("x"))
and_(c1.notilike("x"))
+# issue #9451
+s1 = c1.cast(Integer)
+s2 = c1.cast(Float)
+s3 = c1.op("foobar")("operand").cast(DateTime)
+s4 = cast(c1, Float)
+s5 = cast(c1.op("foobar")("operand"), DateTime)
+
if typing.TYPE_CHECKING: