From 88ef4baca844a75964c0ece99ff248851fbf3f2c Mon Sep 17 00:00:00 2001 From: rocky Date: Mon, 19 Mar 2018 11:10:03 -0400 Subject: [PATCH] Fix a 3.6 try/except-as bug --- test/bytecode_3.6/04_try_finally.pyc | Bin 363 -> 580 bytes test/bytecode_3.6/05_if_and_comp.pyc | Bin 397 -> 695 bytes test/simple_source/bug36/04_try_finally.py | 13 +++++++++++++ test/simple_source/bug36/05_if_and_comp.py | 5 +++++ uncompyle6/parsers/parse3.py | 4 ++-- uncompyle6/parsers/parse36.py | 7 ++++++- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/test/bytecode_3.6/04_try_finally.pyc b/test/bytecode_3.6/04_try_finally.pyc index 15a5adfba5953643a9327bf2989efb8a129970e6..8f7ab09f99a4f7a7eb476a89ed278468b6f7bd40 100644 GIT binary patch delta 308 zcmYjLu}Z{H5Zv9oyTr(aSPEAQX|)r<1JCv>QYdL8xPc2w0-HlQxoG1Lh#z9%FZczP zX|2RBuyYY{AmVsQ;?GK6BVSQ0hHD02r4?x zDGQ&EejcwFW4;0)1x|o&23kkTJ)cvv?`TEWu}ztLE9C@-;T$sc!gTL8lEd%iK`y8P zHjI2(e2tKk$*@yY*3RqOx~tpf)U353Jj?x~uq-f#sljQvDvRK5xi){wANl=Zds#Mm oQ(anB>Mo2f0TByFoUr4RQ!#HX5H*I{mZ#+9nD-(d9feW+3$U*^?f?J) delta 90 zcmX@Y@|wxUn3tF9N!8S-entj{#|%h-3CMN;;$jgXk;0I|*uoISkiwM045S%TSb`Ze cStq*uY5S_ViPfr4hDE7)(q|x#S7S?I(06V RewvI$9Fx15)L4M>3;-77421vy diff --git a/test/simple_source/bug36/04_try_finally.py b/test/simple_source/bug36/04_try_finally.py index 4e0a5a61..1b2d2e49 100644 --- a/test/simple_source/bug36/04_try_finally.py +++ b/test/simple_source/bug36/04_try_finally.py @@ -18,3 +18,16 @@ def getvalue1(self): finally: pass return 2 + +# From Python 3.6 asynchat.py +# Bug is handling as why in the face of a return. +# uncompyle6 shows removal of "why" after the return. +def handle_read(self): + try: + data = 5 + except ZeroDivisionError: + return + except OSError as why: + return why + + return data diff --git a/test/simple_source/bug36/05_if_and_comp.py b/test/simple_source/bug36/05_if_and_comp.py index 46efdcb2..9c4bc61d 100644 --- a/test/simple_source/bug36/05_if_and_comp.py +++ b/test/simple_source/bug36/05_if_and_comp.py @@ -5,3 +5,8 @@ def _85encode(foldnuls, words): return ['z' if foldnuls and word else 'y' for word in words] + +# From Python 3.6 enum.py + +def __new__(metacls, cls, bases, classdict): + {k: classdict[k] for k in classdict._member_names} diff --git a/uncompyle6/parsers/parse3.py b/uncompyle6/parsers/parse3.py index cd3fb13b..a20e671e 100644 --- a/uncompyle6/parsers/parse3.py +++ b/uncompyle6/parsers/parse3.py @@ -240,10 +240,10 @@ class Python3Parser(PythonParser): except_suite ::= returns except_cond1 ::= DUP_TOP expr COMPARE_OP - jmp_false POP_TOP POP_TOP POP_TOP + jmp_false POP_TOP POP_TOP POP_TOP except_cond2 ::= DUP_TOP expr COMPARE_OP - jmp_false POP_TOP store POP_TOP + jmp_false POP_TOP store POP_TOP except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt POP_EXCEPT _jump except ::= POP_TOP POP_TOP POP_TOP returns diff --git a/uncompyle6/parsers/parse36.py b/uncompyle6/parsers/parse36.py index 0391833c..18815bb3 100644 --- a/uncompyle6/parsers/parse36.py +++ b/uncompyle6/parsers/parse36.py @@ -33,9 +33,12 @@ class Python36Parser(Python35Parser): """ sstmt ::= sstmt RETURN_LAST - # 3.6 redoes how return_closure works + # 3.6 redoes how return_closure works. FIXME: Isolate to LOAD_CLOSURE return_closure ::= LOAD_CLOSURE DUP_TOP STORE_NAME RETURN_VALUE RETURN_LAST + # Is there something general going on here? FIXME: Isolate to LOAD_DICTCOMP + dict_comp ::= load_closure LOAD_DICTCOMP LOAD_CONST MAKE_FUNCTION_8 expr GET_ITER CALL_FUNCTION_1 + stmt ::= conditional_lambda conditional_lambda ::= expr jmp_false expr return_if_lambda return_stmt_lambda LAMBDA_MARKER @@ -78,6 +81,8 @@ class Python36Parser(Python35Parser): COME_FROM_FINALLY suite_stmts tryfinally36 ::= SETUP_FINALLY returns COME_FROM_FINALLY suite_stmts_opt END_FINALLY + except_suite_finalize ::= SETUP_FINALLY returns + COME_FROM_FINALLY suite_stmts_opt END_FINALLY _jump """ def customize_grammar_rules(self, tokens, customize):