From 5c8f93b735c13fd4d3aa00260c296e729b02b7cb Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 19 Mar 2018 16:12:44 -0400 Subject: [PATCH] Fix 3.6 try/except with return --- .../bytecode_3.6_run/03_try_return_except.pyc | Bin 0 -> 618 bytes .../bug36/03_try_return_except.py | 30 ++++++++++++++++++ uncompyle6/parsers/parse36.py | 9 ++++++ 3 files changed, 39 insertions(+) create mode 100644 test/bytecode_3.6_run/03_try_return_except.pyc create mode 100644 test/simple_source/bug36/03_try_return_except.py 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 0000000000000000000000000000000000000000..e2336633d695019b1bfb84aa307844a101262164 GIT binary patch literal 618 zcmZutK}!Nr5T1Fi>$+u#L_|b~4#5^wBt(aZBD)G9b^sIv6^8!8pu-0JDoojO zkS-@I2g({SF6|&|ClF-EyXJOjk}^zVf4Tfgp1CeC0B>&g_s|s_#={EVl6mtOAId?> qdWzSsv{n>#!u}0WNb{oK{`Suf@y?$@IqIp4= 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):