Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
d8d63e7f
Commit
d8d63e7f
authored
Jan 09, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support yield inside lambda
parent
bf5eec6d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+12
-5
tests/run/generators.pyx
tests/run/generators.pyx
+12
-0
No files found.
Cython/Compiler/ParseTreeTransforms.py
View file @
d8d63e7f
...
...
@@ -191,14 +191,20 @@ class PostParse(ScopeTrackingTransform):
lambda_id
=
self
.
lambda_counter
self
.
lambda_counter
+=
1
node
.
lambda_name
=
EncodedString
(
u'lambda%d'
%
lambda_id
)
body
=
Nodes
.
ReturnStatNode
(
node
.
result_expr
.
pos
,
value
=
node
.
result_expr
)
collector
=
YieldNodeCollector
()
collector
.
visitchildren
(
node
.
result_expr
)
if
collector
.
yields
or
isinstance
(
node
.
result_expr
,
ExprNodes
.
YieldExprNode
):
body
=
ExprNodes
.
YieldExprNode
(
node
.
result_expr
.
pos
,
arg
=
node
.
result_expr
)
body
=
Nodes
.
ExprStatNode
(
node
.
result_expr
.
pos
,
expr
=
body
)
else
:
body
=
Nodes
.
ReturnStatNode
(
node
.
result_expr
.
pos
,
value
=
node
.
result_expr
)
node
.
def_node
=
Nodes
.
DefNode
(
node
.
pos
,
name
=
node
.
name
,
lambda_name
=
node
.
lambda_name
,
args
=
node
.
args
,
star_arg
=
node
.
star_arg
,
starstar_arg
=
node
.
starstar_arg
,
body
=
body
)
body
=
body
,
doc
=
None
)
self
.
visitchildren
(
node
)
return
node
...
...
@@ -1383,7 +1389,8 @@ class MarkClosureVisitor(CythonTransform):
starstar_arg
=
node
.
starstar_arg
,
doc
=
node
.
doc
,
decorators
=
node
.
decorators
,
gbody
=
gbody
)
gbody
=
gbody
,
lambda_name
=
node
.
lambda_name
)
return
generator
return
node
...
...
tests/run/generators.pyx
View file @
d8d63e7f
...
...
@@ -287,3 +287,15 @@ def test_nested_yield():
StopIteration
"""
yield
(
yield
(
yield
1
))
def
test_inside_lambda
():
"""
>>> obj = test_inside_lambda()()
>>> next(obj)
1
>>> obj.send('a')
2
>>> obj.send('b')
('a', 'b')
"""
return
lambda
:((
yield
1
),
(
yield
2
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment