You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 08:49:51 +08:00
3.6 "assert" and "or" handling bugs
This commit is contained in:
@@ -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
|
||||
|
@@ -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.
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user