From b0931275a257096b9bcaaf4a0720ea8c0a06c800 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 8 Feb 2020 11:46:19 -0500 Subject: [PATCH] Need more precise "assert" for 3.8... Add rule for ifelsestmtl which is needed in 3.8 --- uncompyle6/parsers/parse3.py | 2 +- uncompyle6/parsers/parse37.py | 9 +++++---- uncompyle6/parsers/reducecheck/ifelsestmt.py | 13 +++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index b56384ac..9cf22653 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -1532,7 +1532,7 @@ class Python3Parser(PythonParser): # FIXME: Put more in this table self.reduce_check_table = { "except_handler_else": except_handler_else, - # "ifstmt": ifstmt, + "ifstmt": ifstmt, "ifstmtl": ifstmt, "ifelsestmtc": ifstmt, "ifelsestmt": ifelsestmt, diff --git a/uncompyle6/parsers/parse37.py b/uncompyle6/parsers/parse37.py index 14a0af42..b29dd513 100644 --- a/uncompyle6/parsers/parse37.py +++ b/uncompyle6/parsers/parse37.py @@ -982,11 +982,12 @@ class Python37Parser(Python37BaseParser): return_stmt_lambda ::= ret_expr RETURN_VALUE_LAMBDA return_if_lambda ::= RETURN_END_IF_LAMBDA - stmt ::= return_closure - return_closure ::= LOAD_CLOSURE RETURN_VALUE RETURN_LAST + stmt ::= return_closure + return_closure ::= LOAD_CLOSURE RETURN_VALUE RETURN_LAST - stmt ::= whileTruestmt - ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite _come_froms + stmt ::= whileTruestmt + ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite _come_froms + ifelsestmtl ::= testexpr c_stmts_opt jump_forward_else else_suitec ifstmtl ::= testexpr _ifstmts_jumpl diff --git a/uncompyle6/parsers/reducecheck/ifelsestmt.py b/uncompyle6/parsers/reducecheck/ifelsestmt.py index 8c1612a7..47d2efa9 100644 --- a/uncompyle6/parsers/reducecheck/ifelsestmt.py +++ b/uncompyle6/parsers/reducecheck/ifelsestmt.py @@ -87,11 +87,16 @@ 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. + # Avoid if/else where the "then" is a "raise_stmt1" for an + # assert statemetn. 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 + if stmts in ("c_stmts",) and len(stmts) == 1: + raise_stmt1 = stmts[0] + if ( + raise_stmt1 == "raise_stmt1" and + raise_stmt1[0] in ("LOAD_ASSERT",) + ): + return True # Make sure all of the "come froms" offset at the # end of the "if" come from somewhere inside the "if".