mirror of
https://github.com/github/codeql.git
synced 2026-05-30 19:11:23 +02:00
Python: fold in evaluation-order review-comment fixes from main
After rebasing onto main, apply the substance of upstream review-comment commits (1ef557c972,35faec3db1): - 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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user