mirror of
https://github.com/github/codeql.git
synced 2026-05-31 11:31:23 +02:00
Python: Address Copilot's comments
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
|
||||
|
||||
@@ -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