fix(gen): prevent empty loop for column asserts
This commit is contained in:
@@ -440,7 +440,11 @@ class Generator(p.Stmt.Visitor[ast.stmt], p.Expr.Visitor[ast.expr]):
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
asserts.append(self._make_column_inner_assert(src_location, expr, type))
|
inner_assert: Optional[ast.stmt] = self._make_column_inner_assert(
|
||||||
|
src_location, expr, type
|
||||||
|
)
|
||||||
|
if inner_assert is not None:
|
||||||
|
asserts.append(inner_assert)
|
||||||
return asserts
|
return asserts
|
||||||
|
|
||||||
case (
|
case (
|
||||||
@@ -592,12 +596,15 @@ class Generator(p.Stmt.Visitor[ast.stmt], p.Expr.Visitor[ast.expr]):
|
|||||||
|
|
||||||
def _make_column_inner_assert(
|
def _make_column_inner_assert(
|
||||||
self, src_location: Location, column: ast.expr, type: ColumnType
|
self, src_location: Location, column: ast.expr, type: ColumnType
|
||||||
) -> ast.stmt:
|
) -> Optional[ast.stmt]:
|
||||||
# TODO: improve message, maybe chain contexts
|
# TODO: improve message, maybe chain contexts
|
||||||
col: ast.expr = ast.Name(id="col")
|
col: ast.expr = ast.Name(id="col")
|
||||||
|
body: list[ast.stmt] = self._make_cast_asserts(src_location, col, type.type)
|
||||||
|
if len(body) == 0:
|
||||||
|
return None
|
||||||
return ast.For(
|
return ast.For(
|
||||||
target=col,
|
target=col,
|
||||||
iter=column,
|
iter=column,
|
||||||
body=self._make_cast_asserts(src_location, col, type.type),
|
body=body,
|
||||||
orelse=[],
|
orelse=[],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user