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
Kirill Smelkov
cython
Commits
d4546c4f
Commit
d4546c4f
authored
Mar 07, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix name lookup in class scope
parent
e5b1dccb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
7 deletions
+74
-7
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+18
-7
Cython/Utility/ObjectHandling.c
Cython/Utility/ObjectHandling.c
+17
-0
tests/run/py_classbody.py
tests/run/py_classbody.py
+39
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
d4546c4f
...
...
@@ -1779,13 +1779,24 @@ class NameNode(AtomicExprNode):
elif
entry
.
is_pyglobal
:
assert
entry
.
type
.
is_pyobject
,
"Python global or builtin not a Python object"
interned_cname
=
code
.
intern_identifier
(
self
.
entry
.
name
)
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"GetModuleGlobalName"
,
"ObjectHandling.c"
))
code
.
putln
(
'%s = __Pyx_GetModuleGlobalName(%s); %s'
%
(
self
.
result
(),
interned_cname
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
if
entry
.
scope
.
is_module_scope
:
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"GetModuleGlobalName"
,
"ObjectHandling.c"
))
code
.
putln
(
'%s = __Pyx_GetModuleGlobalName(%s); %s'
%
(
self
.
result
(),
interned_cname
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
else
:
# FIXME: is_pyglobal is also used for class namespace
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"GetNameInClass"
,
"ObjectHandling.c"
))
code
.
putln
(
'%s = __Pyx_GetNameInClass(%s, %s); %s'
%
(
self
.
result
(),
entry
.
scope
.
namespace_cname
,
interned_cname
,
code
.
error_goto_if_null
(
self
.
result
(),
self
.
pos
)))
code
.
put_gotref
(
self
.
py_result
())
elif
entry
.
is_local
or
entry
.
in_closure
or
entry
.
from_closure
or
entry
.
type
.
is_memoryviewslice
:
...
...
Cython/Utility/ObjectHandling.c
View file @
d4546c4f
...
...
@@ -599,6 +599,23 @@ static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
return
result
;
}
/////////////// GetNameInClass.proto ///////////////
static
PyObject
*
__Pyx_GetNameInClass
(
PyObject
*
nmspace
,
PyObject
*
name
);
/*proto*/
/////////////// GetNameInClass ///////////////
//@requires: PyObjectGetAttrStr
//@requires: GetModuleGlobalName
//@substitute: naming
static
PyObject
*
__Pyx_GetNameInClass
(
PyObject
*
nmspace
,
PyObject
*
name
)
{
PyObject
*
result
;
result
=
__Pyx_PyObject_GetAttrStr
(
nmspace
,
name
);
if
(
!
result
)
result
=
__Pyx_GetModuleGlobalName
(
name
);
return
result
;
}
/////////////// GetModuleGlobalName.proto ///////////////
static
CYTHON_INLINE
PyObject
*
__Pyx_GetModuleGlobalName
(
PyObject
*
name
);
/*proto*/
...
...
tests/run/py_classbody.py
0 → 100644
View file @
d4546c4f
# mode: run
# tag: pyclass, global
pyvar
=
2
class
TestPyAttr
(
object
):
"""
>>> TestPyAttr.pyvar # doctest: +ELLIPSIS
Traceback (most recent call last):
AttributeError: ...TestPyAttr...has no attribute 'pyvar'
>>> TestPyAttr.pyval1
3
>>> TestPyAttr.pyval2
2
"""
pyvar
=
3
pyval1
=
pyvar
del
pyvar
pyval2
=
pyvar
import
cython
cdefvar
=
cython
.
declare
(
int
,
10
)
class
TestCdefAttr
(
object
):
"""
>>> TestCdefAttr.cdefvar # doctest: +ELLIPSIS
Traceback (most recent call last):
AttributeError: ...TestCdefAttr...has no attribute 'cdefvar'
>>> TestCdefAttr.cdefval1
11
>>> #TestCdefAttr.cdefval2
"""
cdefvar
=
11
cdefval1
=
cdefvar
del
cdefvar
# cdefval2 = cdefvar # FIXME: doesn't currently work ...
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