target_node = ExprNodes.PyTempNode(self.target.pos, None)
target_node.allocate(code)
interned_cname = code.intern_identifier(self.target.entry.name)
- code.globalstate.use_utility_code(
- UtilityCode.load_cached("GetModuleGlobalName", "ObjectHandling.c"))
- code.putln("%s = __Pyx_GetModuleGlobalName(%s); %s" % (
+ if self.target.entry.scope.is_module_scope:
+ code.globalstate.use_utility_code(
+ UtilityCode.load_cached("GetModuleGlobalName", "ObjectHandling.c"))
+ lookup_func = '__Pyx_GetModuleGlobalName(%s)'
+ else:
+ code.globalstate.use_utility_code(
+ UtilityCode.load_cached("GetNameInClass", "ObjectHandling.c"))
+ lookup_func = '__Pyx_GetNameInClass(%s, %%s)' % (
+ self.target.entry.scope.namespace_cname)
+ code.putln("%s = %s; %s" % (
target_node.result(),
- interned_cname,
+ lookup_func % interned_cname,
code.error_goto_if_null(target_node.result(), self.target.pos)))
code.put_gotref(target_node.result())
else:
target_node = self.target
- from_py_node = ExprNodes.CoerceFromPyTypeNode(self.loopvar_node.type, target_node, None)
+ from_py_node = ExprNodes.CoerceFromPyTypeNode(
+ self.loopvar_node.type, target_node, self.target.entry.scope)
from_py_node.temp_code = loopvar_name
from_py_node.generate_result_code(code)
if self.target.entry.is_pyglobal:
cdef object j = 0
for j in range(size()):
print j
+
+
+class ForFromLoopInPyClass(object):
+ """
+ >>> ForFromLoopInPyClass.i # doctest: +ELLIPSIS
+ Traceback (most recent call last):
+ AttributeError: ...ForLoopInPyClass... has no attribute ...i...
+ >>> ForFromLoopInPyClass.k
+ 0
+ >>> ForFromLoopInPyClass.m
+ 1
+ """
+ for i from 0 <= i < 1:
+ pass
+
+ for k from 0 <= k < 2:
+ pass
+
+ for m from 0 <= m < 3:
+ pass
cdefval1 = cdefvar
del cdefvar
# cdefval2 = cdefvar # FIXME: doesn't currently work ...
+
+
+class ForLoopInPyClass(object):
+ """
+ >>> ForLoopInPyClass.i # doctest: +ELLIPSIS
+ Traceback (most recent call last):
+ AttributeError: ...ForLoopInPyClass... has no attribute ...i...
+ >>> ForLoopInPyClass.k
+ 0
+ >>> ForLoopInPyClass.m
+ 1
+ """
+ for i in range(0):
+ pass
+
+ for k in range(1):
+ pass
+
+ for m in range(2):
+ pass