Fix 3.6 try/except with return

This commit is contained in:
rocky
2018-03-19 16:12:44 -04:00
parent 88ef4baca8
commit 5c8f93b735
3 changed files with 39 additions and 0 deletions

Binary file not shown.

View 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

View File

@@ -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):