diff --git a/test/bytecode_3.6_run/03_try_return_except.pyc b/test/bytecode_3.6_run/03_try_return_except.pyc new file mode 100644 index 00000000..e2336633 Binary files /dev/null and b/test/bytecode_3.6_run/03_try_return_except.pyc differ diff --git a/test/simple_source/bug36/03_try_return_except.py b/test/simple_source/bug36/03_try_return_except.py new file mode 100644 index 00000000..789b175e --- /dev/null +++ b/test/simple_source/bug36/03_try_return_except.py @@ -0,0 +1,30 @@ +# From Python 3.6 bdb.py +# Bug was handling try's with returns +# END_FINALLY in 3.6 starts disasppearing + +def effective(possibles): + for b in possibles: + try: + return 1 + except: + return 2 + return 3 + +assert effective([5]) == 1 +assert effective([]) == 3 + +def effective2(possibles): + b = 0 + for b in possibles: + try: + if b >= 5: + b = 5 + else: + return 2 + except: + return 3 + return b + +assert effective2([5]) == 5 +assert effective2([]) == 0 +assert effective2(['a']) == 3 diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 18815bb3..af990f2b 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -75,6 +75,11 @@ class Python36Parser(Python35Parser): stmt ::= try_except36 try_except36 ::= SETUP_EXCEPT returns except_handler36 opt_come_from_except + try_except36 ::= SETUP_EXCEPT suite_stmts + + # 3.6 omits END_FINALLY sometimes + except_handler36 ::= COME_FROM_EXCEPT except_stmts + except_handler ::= jmp_abs COME_FROM_EXCEPT except_stmts stmt ::= tryfinally36 tryfinally36 ::= SETUP_FINALLY returns @@ -87,6 +92,10 @@ class Python36Parser(Python35Parser): def customize_grammar_rules(self, tokens, customize): super(Python36Parser, self).customize_grammar_rules(tokens, customize) + self.remove_rules(""" + for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK _come_froms + dict_comp ::= load_closure LOAD_DICTCOMP LOAD_CONST MAKE_CLOSURE_0 expr GET_ITER CALL_FUNCTION_1 + """) self.check_reduce['call_kw'] = 'AST' for i, token in enumerate(tokens):