In 2.7: raise <expr>; expr can't be a "or"

This commit is contained in:
rocky
2018-03-20 16:14:53 -04:00
parent 9f2c7352e7
commit ff50a7f37b
3 changed files with 12 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,9 @@
# From 2.7 test_argparse.py
# Bug was turnning assert into an "or raise" statement
def __call__(arg, dest):
try:
assert arg == 'spam', 'dest: %s' % dest
except:
raise
__call__('spam', __file__)

View File

@@ -175,6 +175,7 @@ class Python27Parser(Python2Parser):
""")
super(Python27Parser, self).customize_grammar_rules(tokens, customize)
self.check_reduce['and'] = 'AST'
self.check_reduce['raise_stmt1'] = 'AST'
# self.check_reduce['conditional_true'] = 'AST'
return
@@ -191,6 +192,8 @@ class Python27Parser(Python2Parser):
jmp_target = jmp_false.offset + jmp_false.attr + 3
return not (jmp_target == tokens[last].offset or
tokens[last].pattr == jmp_false.pattr)
elif rule[0] == ('raise_stmt1'):
return ast[0] == 'expr' and ast[0][0] == 'or'
# elif rule[0] == ('conditional_true'):
# # FIXME: the below is a hack: we check expr for
# # nodes that could have possibly been a been a Boolean.