support genexp loop variables that override builtin names or global functions etc.
authorStefan Behnel <scoder@users.berlios.de>
Tue, 25 May 2010 09:24:54 +0000 (11:24 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 25 May 2010 09:24:54 +0000 (11:24 +0200)
Cython/Compiler/Symtab.py
tests/run/any.pyx

index b7b3d65578afb29355fb319bcf045099b08cab00..0c0fccade09dc7ba9439546f8219aa487566e19d 100644 (file)
@@ -1278,7 +1278,7 @@ class GeneratorExpressionScope(LocalScope):
         if type is unspecified_type:
             # if the outer scope defines a type for this variable, inherit it
             outer_entry = self.outer_scope.lookup(name)
-            if outer_entry and not outer_entry.is_builtin:
+            if outer_entry and outer_entry.is_variable:
                 type = outer_entry.type # may still be 'unspecified_type' !
         # the outer scope needs to generate code for the variable, but
         # this scope must hold its name exclusively
index 9c8ce510782815c6701bfb30341c28935155a868..3c31cd971d8c5b29b26bbecdb5e0a2afec682074 100644 (file)
@@ -51,6 +51,7 @@ def any_item(x):
     """
     return any(x)
 
+
 @cython.test_assert_path_exists("//ForInStatNode",
                                 "//InlinedGeneratorExpressionNode")
 @cython.test_fail_if_path_exists("//SimpleCallNode",
@@ -78,6 +79,7 @@ def any_in_simple_gen(seq):
     """
     return any(x for x in seq)
 
+
 @cython.test_assert_path_exists("//ForInStatNode",
                                 "//InlinedGeneratorExpressionNode")
 @cython.test_fail_if_path_exists("//SimpleCallNode",
@@ -108,6 +110,7 @@ def any_in_simple_gen_scope(seq):
     assert x == 'abc'
     return result
 
+
 @cython.test_assert_path_exists("//ForInStatNode",
                                 "//InlinedGeneratorExpressionNode")
 @cython.test_fail_if_path_exists("//SimpleCallNode",
@@ -142,6 +145,7 @@ mixed_ustring = u'AbcDefGhIjKlmnoP'
 lower_ustring = mixed_ustring.lower()
 upper_ustring = mixed_ustring.upper()
 
+
 @cython.test_assert_path_exists('//PythonCapiCallNode',
                                 '//ForFromStatNode',
                                 "//InlinedGeneratorExpressionNode")
@@ -158,6 +162,7 @@ def any_lower_case_characters(unicode ustring):
     """
     return any(uchar.islower() for uchar in ustring)
 
+
 @cython.test_assert_path_exists("//ForInStatNode",
                                 "//InlinedGeneratorExpressionNode",
                                 "//InlinedGeneratorExpressionNode//IfStatNode")
@@ -188,6 +193,36 @@ def any_in_typed_gen(seq):
     cdef int x
     return any(x for x in seq)
 
+
+@cython.test_assert_path_exists("//ForInStatNode",
+                                "//InlinedGeneratorExpressionNode",
+                                "//InlinedGeneratorExpressionNode//IfStatNode")
+@cython.test_fail_if_path_exists("//SimpleCallNode",
+                                 "//YieldExprNode")
+def any_in_gen_builtin_name(seq):
+    """
+    >>> any_in_gen_builtin_name([0,1,0])
+    True
+    >>> any_in_gen_builtin_name([0,0,0])
+    False
+
+    >>> any_in_gen_builtin_name(VerboseGetItem([0,0,1,0,0]))
+    0
+    1
+    2
+    True
+    >>> any_in_gen_builtin_name(VerboseGetItem([0,0,0,0,0]))
+    0
+    1
+    2
+    3
+    4
+    5
+    False
+    """
+    return any(type for type in seq)
+
+
 @cython.test_assert_path_exists("//ForInStatNode",
                                 "//InlinedGeneratorExpressionNode",
                                 "//InlinedGeneratorExpressionNode//IfStatNode")