Work around 2.7 phony come-froms in ifelsesmt

This commit is contained in:
rocky
2020-01-31 15:49:29 -05:00
parent be022b3416
commit f27b72ab05
2 changed files with 5 additions and 2 deletions

View File

@@ -80,7 +80,7 @@ def ifelsestmt(self, lhs, n, rule, ast, tokens, first, last):
# offset COME_FROM is last, it is sufficient to test
# just the last one.
come_froms = ast[-1]
if come_froms.kind != "else_suite":
if come_froms.kind != "else_suite" and self.version >= 3.0:
if come_froms == "opt_come_from_except" and len(come_froms) > 0:
come_froms = come_froms[0]
if not isinstance(come_froms, Token):
@@ -96,7 +96,8 @@ def ifelsestmt(self, lhs, n, rule, ast, tokens, first, last):
else:
last_token = tokens[last]
if last_token == "COME_FROM" and tokens[first].offset > last_token.attr:
return True
if self.version < 3.0 and self.insts[self.offset2inst_index[last_token.attr]].opname != "SETUP_LOOP":
return True
testexpr = ast[0]

View File

@@ -2442,7 +2442,9 @@ class SourceWalker(GenericASTTraversal, object):
# modularity is broken here
p_insts = self.p.insts
self.p.insts = self.scanner.insts
self.p.insts = self.scanner.insts
self.p.opc = self.scanner.opc
self.p.offset2inst_index = self.scanner.offset2inst_index
ast = python_parser.parse(self.p, tokens, customize)
self.p.insts = p_insts
except (python_parser.ParserError, AssertionError) as e: