Merge branch '32-with-statement-control-flow-template-310' into cflow-refactor

This commit is contained in:
caandt
2025-06-12 16:23:43 -05:00
@@ -32,10 +32,64 @@ class With3_11(ControlFlowTemplate):
try_match = make_try_match({EdgeKind.Fall: "normal_cleanup"}, "setup_with", "with_body", "exc_cleanup")
@to_indented_source
def to_indented_source():
"""
{setup_with}
{with_body}
"""
class WithCleanup3_9(ControlFlowTemplate):
template = T(
start=~N("reraise", "poptop").with_cond(
starting_instructions("WITH_EXCEPT_START"), # 3.9 & 3.10
),
reraise=+N().with_cond(exact_instructions("RERAISE")).with_in_deg(1),
poptop=~N("tail.", None).with_cond(starting_instructions("POP_TOP")).with_in_deg(1),
tail=N.tail(),
)
try_match = make_try_match({EdgeKind.Fall: "tail"}, "start", "reraise", "poptop")
@to_indented_source
def to_indented_source(self, source):
"""
{poptop}
"""
@register_template(0, 10, (3, 9), (3, 10))
class With3_9(ControlFlowTemplate):
template = T(
setup_with=~N("with_body", None),
with_body=N("normal_cleanup.", None, "exc_cleanup").with_in_deg(1),
exc_cleanup=N.tail().of_subtemplate(WithCleanup3_9).with_in_deg(1),
normal_cleanup=~N.tail(),
)
try_match = make_try_match({EdgeKind.Fall: "normal_cleanup"}, "setup_with", "with_body", "exc_cleanup")
@to_indented_source
def to_indented_source():
"""
{setup_with}
{with_body}
{exc_cleanup}
"""
@register_template(0, 10, (3, 6), (3, 7), (3, 8))
class With3_6(ControlFlowTemplate):
template = T(
setup_with=~N("with_body", None),
with_body=N("buffer_block.", None, "normal_cleanup").with_in_deg(1),
buffer_block=~N("normal_cleanup.", None).with_in_deg(1),
normal_cleanup=~N.tail(),
)
try_match = make_try_match({EdgeKind.Fall: "normal_cleanup"}, "setup_with", "with_body", "buffer_block")
@to_indented_source
def to_indented_source():
"""
{setup_with}
{with_body}
"""