From ad6df5eb95b1e96da9b6c2c9b037aecdb5cfc692 Mon Sep 17 00:00:00 2001 From: dsad Date: Tue, 28 Jul 2026 01:17:05 +0300 Subject: [PATCH] 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. --- tests/gateway/test_compression_session_id_persistence.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/gateway/test_compression_session_id_persistence.py b/tests/gateway/test_compression_session_id_persistence.py index 2d5bb9413204..f3468cadff3d 100644 --- a/tests/gateway/test_compression_session_id_persistence.py +++ b/tests/gateway/test_compression_session_id_persistence.py @@ -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)):