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
cd36e80c
Commit
cd36e80c
authored
Dec 13, 2010
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error handling add error tests
parent
5e6e3aee
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
9 deletions
+40
-9
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+12
-9
tests/errors/e_generators.pyx
tests/errors/e_generators.pyx
+24
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
cd36e80c
...
@@ -4978,11 +4978,15 @@ class YieldExprNode(ExprNode):
...
@@ -4978,11 +4978,15 @@ class YieldExprNode(ExprNode):
#
#
# arg ExprNode the value to return from the generator
# arg ExprNode the value to return from the generator
# label_name string name of the C label used for this yield
# label_name string name of the C label used for this yield
# label_num integer yield label number
subexprs
=
[
'arg'
]
subexprs
=
[
'arg'
]
type
=
py_object_type
type
=
py_object_type
label_num
=
0
def
analyse_types
(
self
,
env
):
def
analyse_types
(
self
,
env
):
if
not
self
.
label_num
:
error
(
self
.
pos
,
"'yield' not supported here"
)
self
.
is_temp
=
1
self
.
is_temp
=
1
if
self
.
arg
is
not
None
:
if
self
.
arg
is
not
None
:
self
.
arg
.
analyse_types
(
env
)
self
.
arg
.
analyse_types
(
env
)
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
cd36e80c
...
@@ -1308,22 +1308,23 @@ class YieldNodeCollector(TreeVisitor):
...
@@ -1308,22 +1308,23 @@ class YieldNodeCollector(TreeVisitor):
def
__init__
(
self
):
def
__init__
(
self
):
super
(
YieldNodeCollector
,
self
).
__init__
()
super
(
YieldNodeCollector
,
self
).
__init__
()
self
.
yields
=
[]
self
.
yields
=
[]
self
.
has_return
=
False
self
.
returns
=
[]
self
.
has_return_value
=
False
visit_Node
=
TreeVisitor
.
visitchildren
visit_Node
=
TreeVisitor
.
visitchildren
def
visit_YieldExprNode
(
self
,
node
):
def
visit_YieldExprNode
(
self
,
node
):
if
self
.
has_return
:
if
self
.
has_return
_value
:
error
(
node
.
pos
,
"'yield' outside function"
)
error
(
node
.
pos
,
"'yield' outside function"
)
else
:
self
.
yields
.
append
(
node
)
self
.
yields
.
append
(
node
)
node
.
label_num
=
len
(
self
.
yields
)
node
.
label_num
=
len
(
self
.
yields
)
def
visit_ReturnStatNode
(
self
,
node
):
def
visit_ReturnStatNode
(
self
,
node
):
if
node
.
value
:
self
.
has_return_value
=
True
if
self
.
yields
:
if
self
.
yields
:
error
(
collector
.
returns
[
0
].
pos
,
"'return' with argument inside generator"
)
error
(
node
.
pos
,
"'return' with argument inside generator"
)
else
:
self
.
returns
.
append
(
node
)
self
.
has_return
=
True
def
visit_ClassDefNode
(
self
,
node
):
def
visit_ClassDefNode
(
self
,
node
):
pass
pass
...
@@ -1348,6 +1349,8 @@ class MarkClosureVisitor(CythonTransform):
...
@@ -1348,6 +1349,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
:
error
(
collector
.
returns
[
0
].
pos
,
"'return' inside generators not yet supported "
)
node
.
is_generator
=
True
node
.
is_generator
=
True
node
.
needs_closure
=
True
node
.
needs_closure
=
True
node
.
yields
=
collector
.
yields
node
.
yields
=
collector
.
yields
...
...
tests/errors/e_generators.pyx
0 → 100644
View file @
cd36e80c
def
foo
():
yield
return
0
def
bar
(
a
):
return
0
yield
def
xxx
():
yield
return
yield
class
Foo
:
yield
_ERRORS
=
u"""
3:4: 'return' with argument inside generator
7:4: 'yield' outside function
11:4: 'return' inside generators not yet supported
13:0: 'yield' not supported here
16:4: 'yield' not supported here
"""
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