From ef74ec1ff101126c86d8f7821c048a5fa9fb0a65 Mon Sep 17 00:00:00 2001 From: yoff Date: Thu, 28 May 2026 21:12:48 +0000 Subject: [PATCH] Python: fold in evaluation-order review-comment fixes from main After rebasing onto main, apply the substance of upstream review-comment commits (1ef557c972f, 35faec3db1e): - timer.py: stricter validation (raise TypeError for unknown subscript elements), bypass atexit via os._exit on failure. - test_basic.py: simpler test cases per review (drop unnecessary parens, use call form in test_callable_syntax), updated docstring. - TimerUtils.qll: docstring update reflecting the t[dead(n)] / t[never] forms. The 'dead(2)' annotation in test_boolean.py:27 is kept because our NewCfgBranchTimestamps check (added on this branch) requires it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ControlFlow/evaluation-order/TimerUtils.qll | 7 ++++--- .../ControlFlow/evaluation-order/test_basic.py | 10 +++++----- .../ControlFlow/evaluation-order/timer.py | 7 ++++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/python/ql/test/library-tests/ControlFlow/evaluation-order/TimerUtils.qll b/python/ql/test/library-tests/ControlFlow/evaluation-order/TimerUtils.qll index da66bd31b25..46ace2e3e6b 100644 --- a/python/ql/test/library-tests/ControlFlow/evaluation-order/TimerUtils.qll +++ b/python/ql/test/library-tests/ControlFlow/evaluation-order/TimerUtils.qll @@ -1,9 +1,10 @@ /** * Utility library for identifying timer annotations in evaluation-order tests. * - * Identifies `expr @ t[n]` (matmul), `t(expr, n)` (call), and - * `expr @ t.dead[n]` (dead-code) patterns, extracts timestamp values, - * and provides predicates for traversing consecutive annotated CFG nodes. + * Identifies `expr @ t[n]` (matmul) and `t(expr, n)` (call) patterns, + * including `dead(n)` and `never` markers within subscripts, extracts + * timestamp values, and provides predicates for traversing consecutive + * annotated CFG nodes. */ import python diff --git a/python/ql/test/library-tests/ControlFlow/evaluation-order/test_basic.py b/python/ql/test/library-tests/ControlFlow/evaluation-order/test_basic.py index 3e8ee925d91..efea733b0d9 100644 --- a/python/ql/test/library-tests/ControlFlow/evaluation-order/test_basic.py +++ b/python/ql/test/library-tests/ControlFlow/evaluation-order/test_basic.py @@ -5,7 +5,7 @@ are evaluated in the expected order (typically left to right for operands of binary operators, elements of collection literals, etc.) Every evaluated expression has a timestamp annotation, except the -timer mechanism itself (t[n], t.dead[n]). +timer mechanism itself (t[n], t[dead(n)], t[never]). """ from timer import test, never @@ -46,7 +46,7 @@ def test_nested_binary(t): @test def test_chained_add(t): """a + b + c is (a + b) + c: left to right.""" - x = ((1 @ t[0] + 2 @ t[1]) @ t[2] + 3 @ t[3]) @ t[4] + x = (1 @ t[0] + 2 @ t[1] + 3 @ t[2]) @ t[3] @test @@ -58,7 +58,7 @@ def test_mixed_precedence(t): @test def test_string_concat(t): """String concatenation operands: left to right.""" - x = (("hello" @ t[0] + " " @ t[1]) @ t[2] + "world" @ t[3]) @ t[4] + x = ("hello" @ t[0] + " " @ t[1] + "world" @ t[2]) @ t[3] @test @@ -142,8 +142,8 @@ def test_multiple_assignment(t): @test def test_callable_syntax(t): """t(value, n) is equivalent to value @ t[n].""" - x = (1 @ t[0] + 2 @ t[1]) @ t[2] - y = (x @ t[3] * 3 @ t[4]) @ t[5] + x = t(t(1, 0) + t(2, 1), 2) + y = t(t(x, 3) * t(3, 4), 5) @test diff --git a/python/ql/test/library-tests/ControlFlow/evaluation-order/timer.py b/python/ql/test/library-tests/ControlFlow/evaluation-order/timer.py index e10dde2592a..ccec5d64f7c 100644 --- a/python/ql/test/library-tests/ControlFlow/evaluation-order/timer.py +++ b/python/ql/test/library-tests/ControlFlow/evaluation-order/timer.py @@ -26,6 +26,7 @@ Run a test file directly to self-validate: python test_file.py """ import atexit +import os import sys _results = [] @@ -53,6 +54,10 @@ class _Check: self._dead.add(e.timestamp) elif isinstance(e, _NeverSentinel): self._never = True + else: + raise TypeError( + f"Unknown element in timer subscript: {e!r} (type {type(e).__name__})" + ) def __rmatmul__(self, value): ts = self._timer._tick() @@ -183,7 +188,7 @@ def _report(): print("---") print(f"{passed}/{total} tests passed") if passed < total: - sys.exit(1) + os._exit(1) atexit.register(_report)