From d5b742ea8fa5058137d2533a9be0a0824568e067 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Thu, 4 Apr 2024 16:00:32 -0400 Subject: [PATCH] Assert on rather than cast SqlColumnVisitor types. --- .../butler/direct_query_driver/_sql_column_visitor.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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