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
Gwenaël Samain
cython
Commits
4cfcb3cb
Commit
4cfcb3cb
authored
Aug 15, 2011
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lookup variable in globals if not found in pyclass scope, see ticket #671
parent
ffea991b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
24 deletions
+99
-24
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+18
-6
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+1
-1
tests/errors/w_uninitialized_class.pyx
tests/errors/w_uninitialized_class.pyx
+0
-17
tests/run/pyclass_scope_T671.py
tests/run/pyclass_scope_T671.py
+80
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
4cfcb3cb
...
...
@@ -1529,12 +1529,24 @@ class NameNode(AtomicExprNode):
namespace
=
Naming
.
builtins_cname
else
:
# entry.is_pyglobal
namespace
=
entry
.
scope
.
namespace_cname
if
not
self
.
cf_is_null
:
code
.
putln
(
'%s = PyObject_GetItem(%s, %s); %s
'
%
(
'%s = PyObject_GetItem(%s, %s);
'
%
(
self
.
result
(),
namespace
,
interned_cname
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
interned_cname
))
if
self
.
cf_maybe_null
:
if
not
self
.
cf_is_null
:
code
.
putln
(
'if (unlikely(!%s)) {'
%
self
.
result
())
code
.
putln
(
'PyErr_Clear();'
)
code
.
putln
(
'%s = __Pyx_GetName(%s, %s);'
%
(
self
.
result
(),
Naming
.
module_cname
,
interned_cname
))
if
not
self
.
cf_is_null
:
code
.
putln
(
"}"
);
code
.
putln
(
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
))
code
.
put_gotref
(
self
.
py_result
())
elif
entry
.
is_pyglobal
or
entry
.
is_builtin
:
...
...
Cython/Compiler/FlowControl.py
View file @
4cfcb3cb
...
...
@@ -474,7 +474,7 @@ def check_definitions(flow, compiler_directives):
node
.
cf_maybe_null
=
True
if
not
entry
.
from_closure
and
len
(
node
.
cf_state
)
==
1
:
node
.
cf_is_null
=
True
if
node
.
allow_null
or
entry
.
from_closure
:
if
node
.
allow_null
or
entry
.
from_closure
or
entry
.
is_pyclass_attr
:
pass
# Can be uninitialized here
elif
node
.
cf_is_null
:
if
(
entry
.
type
.
is_pyobject
or
entry
.
type
.
is_unspecified
or
...
...
tests/errors/w_uninitialized_class.pyx
deleted
100644 → 0
View file @
ffea991b
# cython: warn.maybe_uninitialized=True
# mode: error
# tag: werror
# class scope
def
foo
(
c
):
class
Foo
(
object
):
if
c
>
0
:
b
=
1
print
a
,
b
a
=
1
return
Foo
_ERRORS
=
"""
10:15: local variable 'a' referenced before assignment
10:18: local variable 'b' might be referenced before assignment
"""
tests/run/pyclass_scope_T671.py
0 → 100644
View file @
4cfcb3cb
# mode: run
# ticket: 671
A
=
1234
class
SimpleAssignment
(
object
):
"""
>>> SimpleAssignment.A
1234
"""
A
=
A
class
SimpleRewrite
(
object
):
"""
>>> SimpleRewrite.A
4321
"""
A
=
4321
A
=
A
def
simple_inner
(
a
):
"""
>>> simple_inner(4321).A
1234
"""
A
=
a
class
X
(
object
):
A
=
A
return
X
def
conditional
(
a
,
cond
):
"""
>>> conditional(4321, False).A
1234
>>> conditional(4321, True).A
4321
"""
class
X
(
object
):
if
cond
:
A
=
a
A
=
A
return
X
def
name_error
():
"""
>>> name_error() #doctest: +ELLIPSIS
Traceback (most recent call last):
...
NameError: ...B...
"""
class
X
(
object
):
B
=
B
def
conditional_name_error
(
cond
):
"""
>>> conditional_name_error(True).B
4321
>>> conditional_name_error(False).B #doctest: +ELLIPSIS
Traceback (most recent call last):
...
NameError: ...B...
"""
class
X
(
object
):
if
cond
:
B
=
4321
B
=
B
return
X
C
=
1111
del
C
def
name_error_deleted
():
"""
>>> name_error_deleted() #doctest: +ELLIPSIS
Traceback (most recent call last):
...
NameError: ...C...
"""
class
X
(
object
):
C
=
C
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