summaryrefslogtreecommitdiff
path: root/as_string.py
diff options
context:
space:
mode:
authorTorsten Marek <tmarek@google.com>2013-03-27 12:29:00 +0100
committerTorsten Marek <tmarek@google.com>2013-03-27 12:29:00 +0100
commit79dc5ed3a1de105fdcd32060e94aa31657bfb2cf (patch)
tree5966411fa8316e2cf3cb32c7fbec6967658cc794 /as_string.py
parent43a095f3d82f6ded5b79786fce06d25c4cf25457 (diff)
downloadastroid-git-79dc5ed3a1de105fdcd32060e94aa31657bfb2cf.tar.gz
Fix inference for generator methods to correctly handle yields in lambdas. Closes #123068
--HG-- branch : stable
Diffstat (limited to 'as_string.py')
-rw-r--r--as_string.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/as_string.py b/as_string.py
index 0a42668d..d3478610 100644
--- a/as_string.py
+++ b/as_string.py
@@ -385,7 +385,11 @@ class AsStringVisitor(object):
def visit_yield(self, node):
"""yield an ast.Yield node as string"""
yi_val = node.value and (" " + node.value.accept(self)) or ""
- return 'yield' + yi_val
+ expr = 'yield' + yi_val
+ if node.parent.is_statement:
+ return expr
+ else:
+ return "(%s)" % (expr,)
class AsStringVisitor3k(AsStringVisitor):