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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
bf1e2133
Commit
bf1e2133
authored
May 28, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make UnboundLocalError message same as in CPython
parent
bc0a7990
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
14 deletions
+20
-14
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+7
-0
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-5
tests/run/uninitialized.pyx
tests/run/uninitialized.pyx
+9
-9
No files found.
Cython/Compiler/Code.py
View file @
bf1e2133
...
...
@@ -1419,6 +1419,13 @@ class CCodeWriter(object):
# return self.putln("if (unlikely(%s < 0)) %s" % (value, self.error_goto(pos))) # TODO this path is almost _never_ taken, yet this macro makes is slower!
return
self
.
putln
(
"if (%s < 0) %s"
%
(
value
,
self
.
error_goto
(
pos
)))
def
put_error_if_unbound
(
self
,
pos
,
entry
):
self
.
put
(
'if (unlikely(!%s)) { '
'PyErr_SetString(PyExc_UnboundLocalError, "'
"local variable '%s' referenced before assignment"
'"); %s }'
%
(
entry
.
cname
,
entry
.
name
,
self
.
error_goto
(
pos
)))
def
set_error_info
(
self
,
pos
):
self
.
funcstate
.
should_declare_error_indicator
=
True
if
self
.
c_line_in_traceback
:
...
...
Cython/Compiler/ExprNodes.py
View file @
bf1e2133
...
...
@@ -1558,9 +1558,9 @@ class NameNode(AtomicExprNode):
elif
entry
.
is_local
or
entry
.
in_closure
or
entry
.
from_closure
:
if
entry
.
type
.
is_pyobject
:
if
(
self
.
cf_maybe_null
or
self
.
cf_is_null
)
and
not
self
.
allow_null
:
code
.
putln
(
'if (unlikely(!%s)) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }'
%
(
entry
.
cname
,
entry
.
name
,
code
.
error_goto
(
self
.
pos
))
)
if
(
self
.
cf_maybe_null
or
self
.
cf_is_null
)
\
and
not
self
.
allow_null
:
code
.
put_error_if_unbound
(
self
.
pos
,
entry
)
def
generate_assignment_code
(
self
,
rhs
,
code
):
#print "NameNode.generate_assignment_code:", self.name ###
...
...
@@ -1693,8 +1693,7 @@ class NameNode(AtomicExprNode):
elif
self
.
entry
.
type
.
is_pyobject
:
if
not
self
.
cf_is_null
:
if
self
.
cf_maybe_null
:
code
.
putln
(
'if (unlikely(!%s)) { PyErr_SetString(PyExc_UnboundLocalError, "%s"); %s }'
%
(
self
.
entry
.
cname
,
self
.
entry
.
name
,
code
.
error_goto
(
self
.
pos
)))
code
.
put_error_if_unbound
(
self
.
pos
,
self
.
entry
)
code
.
put_decref
(
self
.
result
(),
self
.
ctype
())
code
.
putln
(
'%s = NULL;'
%
self
.
result
())
else
:
...
...
tests/run/uninitialized.pyx
View file @
bf1e2133
...
...
@@ -8,7 +8,7 @@ def conditional(cond):
>>> conditional(False)
Traceback (most recent call last):
...
UnboundLocalError:
a
UnboundLocalError:
local variable 'a' referenced before assignment
"""
if
cond
:
a
=
[]
...
...
@@ -21,7 +21,7 @@ def inside_loop(iter):
>>> inside_loop([])
Traceback (most recent call last):
...
UnboundLocalError:
i
UnboundLocalError:
local variable 'i' referenced before assignment
"""
for
i
in
iter
:
pass
...
...
@@ -34,7 +34,7 @@ def try_except(cond):
>>> try_except(False)
Traceback (most recent call last):
...
UnboundLocalError:
a
UnboundLocalError:
local variable 'a' referenced before assignment
"""
try
:
if
cond
:
...
...
@@ -50,7 +50,7 @@ def try_finally(cond):
>>> try_finally(False)
Traceback (most recent call last):
...
UnboundLocalError:
a
UnboundLocalError:
local variable 'a' referenced before assignment
"""
try
:
if
cond
:
...
...
@@ -66,7 +66,7 @@ def deleted(cond):
>>> deleted(True)
Traceback (most recent call last):
...
UnboundLocalError:
a
UnboundLocalError:
local variable 'a' referenced before assignment
"""
a
=
{}
if
cond
:
...
...
@@ -80,7 +80,7 @@ def test_nested(cond):
>>> test_nested(False)
Traceback (most recent call last):
...
UnboundLocalError:
a
UnboundLocalError:
local variable 'a' referenced before assignment
"""
if
cond
:
def
a
():
...
...
@@ -94,7 +94,7 @@ def test_outer(cond):
>>> test_outer(False)
Traceback (most recent call last):
...
UnboundLocalError:
a
UnboundLocalError:
local variable 'a' referenced before assignment
"""
if
cond
:
a
=
{}
...
...
@@ -109,7 +109,7 @@ def test_inner(cond):
>>> test_inner(False)
Traceback (most recent call last):
...
UnboundLocalError:
a
UnboundLocalError:
local variable 'a' referenced before assignment
"""
if
cond
:
a
=
{}
...
...
@@ -124,7 +124,7 @@ def test_class(cond):
>>> test_class(False)
Traceback (most recent call last):
...
UnboundLocalError:
A
UnboundLocalError:
local variable 'A' referenced before assignment
"""
if
cond
:
class
A
:
...
...
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