From fdd784680b6d2a87fec8cc89982aba1836cc7bbf Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Tue, 25 May 2010 11:24:54 +0200 Subject: [PATCH] support genexp loop variables that override builtin names or global functions etc. --- Cython/Compiler/Symtab.py | 2 +- tests/run/any.pyx | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index b7b3d655..0c0fccad 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -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 diff --git a/tests/run/any.pyx b/tests/run/any.pyx index 9c8ce510..3c31cd97 100644 --- a/tests/run/any.pyx +++ b/tests/run/any.pyx @@ -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") -- 2.26.2