if bug in lambda with ifelse

A synergy of Python's irregular lambda, its custom ifelse syntax and its
marvelous indentation regime. Fixes #130
This commit is contained in:
rocky
2017-10-05 11:00:55 -04:00
parent 86305097d2
commit b3359439f9
9 changed files with 46 additions and 8 deletions

View File

@@ -660,6 +660,7 @@ class SourceWalker(GenericASTTraversal, object):
def n_return_if_stmt(self, node):
if self.params['isLambda']:
self.write(' return ')
self.preorder(node[0])
self.prune()
else:
@@ -2129,6 +2130,11 @@ class SourceWalker(GenericASTTraversal, object):
# assert isinstance(tokens[0], Token)
if isLambda:
for t in tokens:
if t.type == 'RETURN_END_IF':
t.type = 'RETURN_END_IF_LAMBDA'
elif t.type == 'RETURN_VALUE':
t.type = 'RETURN_VALUE_LAMBDA'
tokens.append(Token('LAMBDA_MARKER'))
try:
ast = python_parser.parse(self.p, tokens, customize)
@@ -2143,7 +2149,7 @@ class SourceWalker(GenericASTTraversal, object):
# than fight (with the grammar to not emit "return None").
if self.hide_internal:
if len(tokens) >= 2 and not noneInNames:
if tokens[-1].type == 'RETURN_VALUE':
if tokens[-1].type in ('RETURN_VALUE', 'RETURN_VALUE_LAMBDA'):
# Python 3.4's classes can add a "return None" which is
# invalid syntax.
if tokens[-2].type == 'LOAD_CONST':