You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Fix 3.6 try/except with return
This commit is contained in:
BIN
test/bytecode_3.6_run/03_try_return_except.pyc
Normal file
BIN
test/bytecode_3.6_run/03_try_return_except.pyc
Normal file
Binary file not shown.
30
test/simple_source/bug36/03_try_return_except.py
Normal file
30
test/simple_source/bug36/03_try_return_except.py
Normal file
@@ -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
|
@@ -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):
|
||||
|
Reference in New Issue
Block a user