mirror of
https://github.com/syssec-utd/pylingual.git
synced 2026-05-10 18:39:03 -07:00
With.py 3.11
With 3.11 template edits which is similar to 3.12 and 3.13
This commit is contained in:
@@ -2,12 +2,10 @@ from typing import override
|
||||
from ..cft import ControlFlowTemplate, EdgeKind, register_template
|
||||
from ..utils import T, N, exact_instructions, starting_instructions, to_indented_source, make_try_match, versions_from
|
||||
|
||||
|
||||
class WithCleanup3_12(ControlFlowTemplate):
|
||||
class WithCleanup3_11(ControlFlowTemplate):
|
||||
template = T(
|
||||
start=N("reraise", "poptop", "exc").with_cond(
|
||||
exact_instructions("PUSH_EXC_INFO", "WITH_EXCEPT_START", "POP_JUMP_IF_TRUE"), # 3.12
|
||||
exact_instructions("PUSH_EXC_INFO", "WITH_EXCEPT_START", "TO_BOOL", "POP_JUMP_IF_TRUE"), # 3.13
|
||||
starting_instructions("PUSH_EXC_INFO", "WITH_EXCEPT_START"), # 3.11 and later
|
||||
),
|
||||
reraise=N(None, None, "exc").with_cond(exact_instructions("RERAISE")).with_in_deg(1),
|
||||
poptop=N("tail", None, "exc").with_cond(exact_instructions("POP_TOP")).with_in_deg(1),
|
||||
@@ -17,16 +15,17 @@ class WithCleanup3_12(ControlFlowTemplate):
|
||||
|
||||
try_match = make_try_match({}, "start", "reraise", "poptop", "exc", "tail")
|
||||
|
||||
@override
|
||||
@to_indented_source
|
||||
def to_indented_source(self, source):
|
||||
return []
|
||||
"""
|
||||
{tail}
|
||||
"""
|
||||
|
||||
|
||||
@register_template(0, 10, *versions_from(3, 12))
|
||||
@register_template(0, 10, (3, 11), (3, 12), (3, 13))
|
||||
class With3_12(ControlFlowTemplate):
|
||||
template = T(
|
||||
setup_with=~N("with_body", None),
|
||||
with_body=N("normal_cleanup", None, "exc_cleanup").with_in_deg(1),
|
||||
with_body=N("normal_cleanup.", None, "exc_cleanup").with_in_deg(1),
|
||||
exc_cleanup=N.tail().of_subtemplate(WithCleanup3_12).with_in_deg(1),
|
||||
normal_cleanup=~N.tail(),
|
||||
)
|
||||
@@ -38,4 +37,5 @@ class With3_12(ControlFlowTemplate):
|
||||
"""
|
||||
{setup_with}
|
||||
{with_body}
|
||||
"""
|
||||
{exc_cleanup}
|
||||
"""
|
||||
Reference in New Issue
Block a user