Assertion 3.6/3.7/3.8

This commit is contained in:
Xinlong Hu
2025-07-10 11:48:03 -05:00
parent 6a63b8130a
commit 32e548e22a
2 changed files with 1 additions and 15 deletions
@@ -1,9 +1,5 @@
from ..cft import ControlFlowTemplate, EdgeKind, register_template
<<<<<<< Updated upstream
from ..utils import T, N, defer_source_to, run_is, with_instructions, has_instval, starting_instructions, to_indented_source, make_try_match, without_top_level_instructions
=======
from ..utils import T, N, defer_source_to, run_is, has_no_lines, with_instructions, has_instval, starting_instructions, to_indented_source, make_try_match, without_top_level_instructions
>>>>>>> Stashed changes
@register_template(1, 40)
@@ -50,17 +46,10 @@ class IfThen(ControlFlowTemplate):
class Assertion(ControlFlowTemplate):
template = T(
assertion=~N("fail", "tail"),
<<<<<<< Updated upstream
fail=+N().with_cond(starting_instructions("LOAD_ASSERTION_ERROR"), has_instval("LOAD_GLOBAL", argval = "AssertionError")),
tail=N.tail(),
=======
fail=+N().with_cond(starting_instructions("LOAD_ASSERTION_ERROR"), has_instval("LOAD_GLOBAL", argval = "AssertionError")).with_cond(has_no_lines),
tail=N.tail().with_cond(without_top_level_instructions("RERAISE", "END_FINALLY")),
>>>>>>> Stashed changes
tail=N.tail(),
)
try_match = make_try_match({EdgeKind.Fall: "tail"}, "assertion", "fail")
to_indented_source = defer_source_to("assertion")
@@ -129,13 +129,10 @@ def has_instval(opname: str, argval : Any):
return check_instructions
<<<<<<< Updated upstream
=======
def has_no_lines(cfg: CFG, node: ControlFlowTemplate | None) -> bool:
return node is None or all(i.starts_line is None for i in node.get_instructions())
>>>>>>> Stashed changes
def run_is(n: int):
def check_run(cfg: CFG, node: ControlFlowTemplate | None) -> bool:
return cfg.run == n