Commit d4546c4f authored by Stefan Behnel's avatar Stefan Behnel

fix name lookup in class scope

parent e5b1dccb
......@@ -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:
......
......@@ -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*/
......
# 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 ...
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment