test(compression): recurse into control-flow stmts in AST walker

The structural AST walker in test_compression_session_id_persistence.py
only recursed into control-flow children found via iter_child_nodes(stmt).
When a session_entry.session_id assignment lives inside an `else` block
whose statements are all assigns (no nested If/Try/etc to trigger
_walk_node), the assignment was invisible to the walker and the test
florped with 'No assignments found'.

Walk the stmt itself when it is a control-flow node so its
body/orelse/finalbody (and Try handlers) are always expanded, regardless
of whether iter_child_nodes yields an inner control-flow child.
This commit is contained in:
dsad 2026-07-28 01:17:05 +03:00 committed by kshitij
parent f6abc6a046
commit ad6df5eb95

View file

@ -67,6 +67,13 @@ def _session_id_assignments_followed_by_save(source: str) -> list[tuple[int, boo
for i, stmt in enumerate(body):
if self._is_session_id_assign(stmt):
results.append((stmt.lineno, self._block_has_save_after(body, i)))
# Recurse into the stmt itself when it is a control-flow node
# whose body/orelse/finalbody may carry assignments that are
# not also reachable as iter_child_nodes children of the stmt
# (e.g. an ``else`` block whose statements are all assigns).
if isinstance(stmt, (ast.If, ast.For, ast.While, ast.With,
ast.Try, ast.AsyncWith, ast.AsyncFor)):
self._walk_node(stmt)
for child in ast.iter_child_nodes(stmt):
if isinstance(child, (ast.If, ast.For, ast.While, ast.With,
ast.Try, ast.AsyncWith, ast.AsyncFor)):