Skip to content

Commit ef74ec1

Browse files
yoffCopilot
andcommitted
Python: fold in evaluation-order review-comment fixes from main
After rebasing onto main, apply the substance of upstream review-comment commits (1ef557c, 35faec3): - 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>
1 parent 2e82990 commit ef74ec1

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

python/ql/test/library-tests/ControlFlow/evaluation-order/TimerUtils.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* Utility library for identifying timer annotations in evaluation-order tests.
33
*
4-
* Identifies `expr @ t[n]` (matmul), `t(expr, n)` (call), and
5-
* `expr @ t.dead[n]` (dead-code) patterns, extracts timestamp values,
6-
* and provides predicates for traversing consecutive annotated CFG nodes.
4+
* Identifies `expr @ t[n]` (matmul) and `t(expr, n)` (call) patterns,
5+
* including `dead(n)` and `never` markers within subscripts, extracts
6+
* timestamp values, and provides predicates for traversing consecutive
7+
* annotated CFG nodes.
78
*/
89

910
import python

python/ql/test/library-tests/ControlFlow/evaluation-order/test_basic.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
operands of binary operators, elements of collection literals, etc.)
66
77
Every evaluated expression has a timestamp annotation, except the
8-
timer mechanism itself (t[n], t.dead[n]).
8+
timer mechanism itself (t[n], t[dead(n)], t[never]).
99
"""
1010

1111
from timer import test, never
@@ -46,7 +46,7 @@ def test_nested_binary(t):
4646
@test
4747
def test_chained_add(t):
4848
"""a + b + c is (a + b) + c: left to right."""
49-
x = ((1 @ t[0] + 2 @ t[1]) @ t[2] + 3 @ t[3]) @ t[4]
49+
x = (1 @ t[0] + 2 @ t[1] + 3 @ t[2]) @ t[3]
5050

5151

5252
@test
@@ -58,7 +58,7 @@ def test_mixed_precedence(t):
5858
@test
5959
def test_string_concat(t):
6060
"""String concatenation operands: left to right."""
61-
x = (("hello" @ t[0] + " " @ t[1]) @ t[2] + "world" @ t[3]) @ t[4]
61+
x = ("hello" @ t[0] + " " @ t[1] + "world" @ t[2]) @ t[3]
6262

6363

6464
@test
@@ -142,8 +142,8 @@ def test_multiple_assignment(t):
142142
@test
143143
def test_callable_syntax(t):
144144
"""t(value, n) is equivalent to value @ t[n]."""
145-
x = (1 @ t[0] + 2 @ t[1]) @ t[2]
146-
y = (x @ t[3] * 3 @ t[4]) @ t[5]
145+
x = t(t(1, 0) + t(2, 1), 2)
146+
y = t(t(x, 3) * t(3, 4), 5)
147147

148148

149149
@test

python/ql/test/library-tests/ControlFlow/evaluation-order/timer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def test_sequential(t):
2626
"""
2727

2828
import atexit
29+
import os
2930
import sys
3031

3132
_results = []
@@ -53,6 +54,10 @@ def __init__(self, timer, elements):
5354
self._dead.add(e.timestamp)
5455
elif isinstance(e, _NeverSentinel):
5556
self._never = True
57+
else:
58+
raise TypeError(
59+
f"Unknown element in timer subscript: {e!r} (type {type(e).__name__})"
60+
)
5661

5762
def __rmatmul__(self, value):
5863
ts = self._timer._tick()
@@ -183,7 +188,7 @@ def _report():
183188
print("---")
184189
print(f"{passed}/{total} tests passed")
185190
if passed < total:
186-
sys.exit(1)
191+
os._exit(1)
187192

188193

189194
atexit.register(_report)

0 commit comments

Comments
 (0)