3.6 "assert" and "or" handling bugs

This commit is contained in:
rocky
2020-02-08 06:42:24 -05:00
parent 946d46a574
commit 7c73536b4a
6 changed files with 24 additions and 12 deletions

View File

@@ -87,6 +87,12 @@ def ifelsestmt(self, lhs, n, rule, ast, tokens, first, last):
if rule not in IFELSE_STMT_RULES:
return False
# Avoid if/else where the "then" is a "raise_stmt1". Parse this
# as an "assert" instead.
stmts = ast[1]
if stmts in ("c_stmts",) and len(stmts) == 1 and stmts[0] == "raise_stmt1":
return True
# Make sure all of the "come froms" offset at the
# end of the "if" come from somewhere inside the "if".
# Since the come_froms are ordered so that lowest

View File

@@ -7,7 +7,9 @@ def ifstmt(self, lhs, n, rule, ast, tokens, first, last):
last -= 1
pass
if tokens[last].attr and isinstance(tokens[last].attr, int):
return tokens[first].offset < tokens[last].attr
if tokens[first].offset >= tokens[last].attr:
return True
pass
pass
# Make sure jumps don't extend beyond the end of the if statement.

View File

@@ -1,9 +1,9 @@
# Copyright (c) 2020 Rocky Bernstein
ASSERT_OPS = frozenset(["LOAD_ASSERT", "RAISE_VARARGS_1"])
def or_check(self, lhs, n, rule, ast, tokens, first, last):
if rule == ("or", ("expr", "jmp_true", "expr")):
if tokens[last] in ("LOAD_ASSERT", "RAISE_VARARGS_1",):
if tokens[last] in ASSERT_OPS or tokens[last-1] in ASSERT_OPS:
return True
# The following test is be the most accurate. It prevents "or" from being