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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
e0afd5f8
Commit
e0afd5f8
authored
May 25, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let generator expressions inherit type declarations from surrounding scope
parent
a2e8d257
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
17 deletions
+23
-17
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+5
-0
tests/run/all.pyx
tests/run/all.pyx
+8
-8
tests/run/any.pyx
tests/run/any.pyx
+10
-9
No files found.
Cython/Compiler/Symtab.py
View file @
e0afd5f8
...
...
@@ -1275,6 +1275,11 @@ class GeneratorExpressionScope(LocalScope):
def declare_var(self, name, type, pos,
cname = None, visibility = '
private
', is_cdef = True):
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:
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
cname = '
%
s
%
s
' % (self.genexp_prefix, self.outer_scope.mangle(Naming.var_prefix, name))
...
...
tests/run/all.pyx
View file @
e0afd5f8
...
...
@@ -166,9 +166,11 @@ def all_lower_case_characters(unicode ustring):
return
all
(
uchar
.
islower
()
for
uchar
in
ustring
)
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
)
"//InlinedGeneratorExpressionNode"
,
"//InlinedGeneratorExpressionNode//IfStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
,
"//YieldExprNode"
)
"//YieldExprNode"
,
"//IfStatNode//CoerceToBooleanNode"
)
def
all_in_typed_gen
(
seq
):
"""
>>> all_in_typed_gen([1,1,1])
...
...
@@ -192,15 +194,15 @@ def all_in_typed_gen(seq):
4
False
"""
# FIXME: this isn't really supposed to work, but it currently does
# due to incorrect scoping - this should be fixed!!
cdef
int
x
return
all
(
x
for
x
in
seq
)
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
)
"//InlinedGeneratorExpressionNode"
,
"//InlinedGeneratorExpressionNode//IfStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
,
"//YieldExprNode"
)
"//YieldExprNode"
,
"//IfStatNode//CoerceToBooleanNode"
)
def
all_in_nested_gen
(
seq
):
"""
>>> all(x for L in [[1,1,1],[1,1,1],[1,1,1]] for x in L)
...
...
@@ -243,7 +245,5 @@ def all_in_nested_gen(seq):
2
False
"""
# FIXME: this isn't really supposed to work, but it currently does
# due to incorrect scoping - this should be fixed!!
cdef
int
x
return
all
(
x
for
L
in
seq
for
x
in
L
)
tests/run/any.pyx
View file @
e0afd5f8
...
...
@@ -143,7 +143,8 @@ lower_ustring = mixed_ustring.lower()
upper_ustring
=
mixed_ustring
.
upper
()
@
cython
.
test_assert_path_exists
(
'//PythonCapiCallNode'
,
'//ForFromStatNode'
)
'//ForFromStatNode'
,
"//InlinedGeneratorExpressionNode"
)
@
cython
.
test_fail_if_path_exists
(
'//SimpleCallNode'
,
'//ForInStatNode'
)
def
any_lower_case_characters
(
unicode
ustring
):
...
...
@@ -158,9 +159,11 @@ def any_lower_case_characters(unicode ustring):
return
any
(
uchar
.
islower
()
for
uchar
in
ustring
)
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
)
"//InlinedGeneratorExpressionNode"
,
"//InlinedGeneratorExpressionNode//IfStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
,
"//YieldExprNode"
)
"//YieldExprNode"
,
"//IfStatNode//CoerceToBooleanNode"
)
def
any_in_typed_gen
(
seq
):
"""
>>> any_in_typed_gen([0,1,0])
...
...
@@ -182,15 +185,15 @@ def any_in_typed_gen(seq):
5
False
"""
# FIXME: this isn't really supposed to work, but it currently does
# due to incorrect scoping - this should be fixed!!
cdef
int
x
return
any
(
x
for
x
in
seq
)
@
cython
.
test_assert_path_exists
(
"//ForInStatNode"
,
"//InlinedGeneratorExpressionNode"
)
"//InlinedGeneratorExpressionNode"
,
"//InlinedGeneratorExpressionNode//IfStatNode"
)
@
cython
.
test_fail_if_path_exists
(
"//SimpleCallNode"
,
"//YieldExprNode"
)
"//YieldExprNode"
,
"//IfStatNode//CoerceToBooleanNode"
)
def
any_in_nested_gen
(
seq
):
"""
>>> any(x for L in [[0,0,0],[0,0,1],[0,0,0]] for x in L)
...
...
@@ -226,7 +229,5 @@ def any_in_nested_gen(seq):
3
False
"""
# FIXME: this isn't really supposed to work, but it currently does
# due to incorrect scoping - this should be fixed!!
cdef
int
x
return
any
(
x
for
L
in
seq
for
x
in
L
)
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