diff --git a/python/lsst/daf/butler/direct_query_driver/_sql_column_visitor.py b/python/lsst/daf/butler/direct_query_driver/_sql_column_visitor.py index d1929a8720..57ae49fb5f 100644 --- a/python/lsst/daf/butler/direct_query_driver/_sql_column_visitor.py +++ b/python/lsst/daf/butler/direct_query_driver/_sql_column_visitor.py @@ -29,7 +29,7 @@ __all__ = ("SqlColumnVisitor",) -from typing import TYPE_CHECKING, Any, cast +from typing import TYPE_CHECKING, Any import sqlalchemy @@ -257,7 +257,11 @@ def apply_logical_not( return sqlalchemy.not_(result) def expect_scalar(self, expression: qt.OrderExpression) -> sqlalchemy.ColumnElement[Any]: - return cast(sqlalchemy.ColumnElement[Any], expression.visit(self)) + result = expression.visit(self) + assert isinstance(result, sqlalchemy.ColumnElement) + return result def expect_timespan(self, expression: qt.ColumnExpression) -> TimespanDatabaseRepresentation: - return cast(TimespanDatabaseRepresentation, expression.visit(self)) + result = expression.visit(self) + assert isinstance(result, TimespanDatabaseRepresentation) + return result