fix(guardrails): keep visit_AsyncFor's result typed

The type-check gate measures in .venv-typecheck, where RestrictedPython is
not installed, so `self.visit_For(node)` is Unknown there. Binding it to
`transformed` and passing it on added one reportUnknownVariableType and one
reportUnknownArgumentType over the merge-base ceiling.

`guard_iter` rewrites `node.iter` on the node it is given and returns that
same node, so keep working on `node`. In that environment sandbox.py now has
18 reportUnknownVariableType (base 19) and 2 reportUnknownArgumentType
(base 2). All 67 tests in test_custom_code_security.py pass.
This commit is contained in:
LeizhenZhang 2026-10-25 14:58:44 -05:00
parent 32dbbeaefe
commit 74c3bb2f06

View file

@ -82,9 +82,10 @@ class AsyncAwareTransformer(RestrictingNodeTransformer):
return bounded
def visit_AsyncFor(self, node: ast.AsyncFor) -> ast.AST:
transformed: Final = self.visit_For(node)
_use_async_iter_guards(transformed)
return transformed
# `guard_iter` rewrites `node.iter` on the node it is given and returns it.
self.visit_For(node)
_use_async_iter_guards(node)
return node
def visit_AsyncWith(self, node: ast.AsyncWith) -> ast.AST:
return self.visit_With(node)