2.7 bug confusing "or" with "if" and "assert"

This commit is contained in:
rocky
2018-03-21 13:18:18 -04:00
parent cf5445c202
commit 0c3db340fa
2 changed files with 9 additions and 1 deletions

View File

@@ -7,3 +7,11 @@ def __call__(arg, dest):
raise raise
__call__('spam', __file__) __call__('spam', __file__)
# From python 2.7.14 lib2to3/refactor.py
# Bug was mangling assert turning if into "or"
def refactor_doctest(clipped, new):
assert clipped, clipped
if not new:
new += u"\n"
return

View File

@@ -538,7 +538,7 @@ class Python2Parser(PythonParser):
# if lhs == 'while1elsestmt': # if lhs == 'while1elsestmt':
# from trepan.api import debug; debug() # from trepan.api import debug; debug()
if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] == 'and': if lhs in ('aug_assign1', 'aug_assign2') and ast[0] and ast[0][0] in ('and', 'or'):
return True return True
if rule == ('or', ('expr', 'jmp_true', 'expr', '\\e_come_from_opt')): if rule == ('or', ('expr', 'jmp_true', 'expr', '\\e_come_from_opt')):
expr2 = ast[2] expr2 = ast[2]