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
f21bcbec
Commit
f21bcbec
authored
Jan 09, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for return with no value inside generator
parent
4bc0e6b1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
10 deletions
+20
-10
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+1
-1
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+2
-2
tests/errors/e_generators.pyx
tests/errors/e_generators.pyx
+2
-7
tests/run/generators.pyx
tests/run/generators.pyx
+15
-0
No files found.
Cython/Compiler/Nodes.py
View file @
f21bcbec
...
@@ -3019,7 +3019,7 @@ class GeneratorBodyDefNode(DefNode):
...
@@ -3019,7 +3019,7 @@ class GeneratorBodyDefNode(DefNode):
# ----- Non-error return cleanup
# ----- Non-error return cleanup
code
.
put_label
(
code
.
return_label
)
code
.
put_label
(
code
.
return_label
)
code
.
put_xdecref
(
Naming
.
retval_cname
,
py_object_type
)
code
.
putln
(
'%s->%s.resume_label = -1;'
%
(
Naming
.
cur_scope_cname
,
Naming
.
obj_base_cname
))
code
.
putln
(
'%s->%s.resume_label = -1;'
%
(
Naming
.
cur_scope_cname
,
Naming
.
obj_base_cname
))
code
.
put_finish_refcount_context
()
code
.
put_finish_refcount_context
()
code
.
putln
(
'return NULL;'
);
code
.
putln
(
'return NULL;'
);
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
f21bcbec
...
@@ -1370,8 +1370,8 @@ class MarkClosureVisitor(CythonTransform):
...
@@ -1370,8 +1370,8 @@ class MarkClosureVisitor(CythonTransform):
collector
.
visitchildren
(
node
)
collector
.
visitchildren
(
node
)
if
collector
.
yields
:
if
collector
.
yields
:
if
collector
.
returns
and
not
collector
.
has_return_value
:
#
if collector.returns and not collector.has_return_value:
error
(
collector
.
returns
[
0
].
pos
,
"'return' inside generators not yet supported "
)
#
error(collector.returns[0].pos, "'return' inside generators not yet supported ")
gbody
=
Nodes
.
GeneratorBodyDefNode
(
pos
=
node
.
pos
,
gbody
=
Nodes
.
GeneratorBodyDefNode
(
pos
=
node
.
pos
,
name
=
node
.
name
,
name
=
node
.
name
,
...
...
tests/errors/e_generators.pyx
View file @
f21bcbec
...
@@ -6,10 +6,6 @@ def bar(a):
...
@@ -6,10 +6,6 @@ def bar(a):
return
0
return
0
yield
yield
def
xxx
():
yield
return
yield
yield
class
Foo
:
class
Foo
:
...
@@ -18,7 +14,6 @@ class Foo:
...
@@ -18,7 +14,6 @@ class Foo:
_ERRORS
=
u"""
_ERRORS
=
u"""
3:4: 'return' with argument inside generator
3:4: 'return' with argument inside generator
7:4: 'yield' outside function
7:4: 'yield' outside function
11:4: 'return' inside generators not yet supported
9:0: 'yield' not supported here
13:0: 'yield' not supported here
12:4: 'yield' not supported here
16:4: 'yield' not supported here
"""
"""
tests/run/generators.pyx
View file @
f21bcbec
...
@@ -244,3 +244,18 @@ def test_decorated(*args):
...
@@ -244,3 +244,18 @@ def test_decorated(*args):
for
i
in
args
:
for
i
in
args
:
yield
i
yield
i
def
test_return
(
a
):
"""
>>> d = dict()
>>> obj = test_return(d)
>>> next(obj)
1
>>> next(obj)
Traceback (most recent call last):
StopIteration
>>> d['i_was_here']
True
"""
yield
1
a
[
'i_was_here'
]
=
True
return
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