2
cdef class VerboseGetItem(object):
4
def __init__(self, seq):
6
def __getitem__(self, i):
8
return self.sequence[i] # may raise IndexError
13
@cython.test_assert_path_exists("//SimpleCallNode")
14
@cython.test_fail_if_path_exists("//ForInStatNode")
17
>>> any_item([0,0,1,0,0])
19
>>> any_item([0,0,0,0,1])
21
>>> any_item([0,0,0,0,0])
24
>>> any(VerboseGetItem([0,0,1,0,0]))
29
>>> any_item(VerboseGetItem([0,0,1,0,0]))
35
>>> any(VerboseGetItem([0,0,0,0,0]))
43
>>> any_item(VerboseGetItem([0,0,0,0,0]))
55
@cython.test_assert_path_exists(
57
"//InlinedGeneratorExpressionNode"
59
@cython.test_fail_if_path_exists(
63
def any_in_simple_gen(seq):
65
>>> any_in_simple_gen([0,1,0])
67
>>> any_in_simple_gen([0,0,0])
70
>>> any_in_simple_gen(VerboseGetItem([0,0,1,0,0]))
75
>>> any_in_simple_gen(VerboseGetItem([0,0,0,0,0]))
84
return any(x for x in seq)
87
@cython.test_assert_path_exists(
89
"//InlinedGeneratorExpressionNode"
91
@cython.test_fail_if_path_exists(
95
def any_in_simple_gen_scope(seq):
97
>>> any_in_simple_gen_scope([0,1,0])
99
>>> any_in_simple_gen_scope([0,0,0])
102
>>> any_in_simple_gen_scope(VerboseGetItem([0,0,1,0,0]))
107
>>> any_in_simple_gen_scope(VerboseGetItem([0,0,0,0,0]))
117
result = any(x for x in seq)
122
@cython.test_assert_path_exists(
124
"//InlinedGeneratorExpressionNode"
126
@cython.test_fail_if_path_exists(
130
def any_in_conditional_gen(seq):
132
>>> any_in_conditional_gen([3,6,9])
134
>>> any_in_conditional_gen([0,3,7])
136
>>> any_in_conditional_gen([1,0,1])
139
>>> any_in_conditional_gen(VerboseGetItem([0,0,3,0,0]))
147
>>> any_in_conditional_gen(VerboseGetItem([0,3,0,1,1]))
154
return any(x%3 for x in seq if x%2 == 1)
156
mixed_ustring = u'AbcDefGhIjKlmnoP'
157
lower_ustring = mixed_ustring.lower()
158
upper_ustring = mixed_ustring.upper()
161
@cython.test_assert_path_exists(
162
'//PythonCapiCallNode',
164
"//InlinedGeneratorExpressionNode"
166
@cython.test_fail_if_path_exists(
170
def any_lower_case_characters(unicode ustring):
172
>>> any_lower_case_characters(upper_ustring)
174
>>> any_lower_case_characters(mixed_ustring)
176
>>> any_lower_case_characters(lower_ustring)
179
return any(uchar.islower() for uchar in ustring)
182
@cython.test_assert_path_exists(
184
"//InlinedGeneratorExpressionNode",
185
"//InlinedGeneratorExpressionNode//IfStatNode"
187
@cython.test_fail_if_path_exists(
190
# "//IfStatNode//CoerceToBooleanNode"
192
def any_in_typed_gen(seq):
194
>>> any_in_typed_gen([0,1,0])
196
>>> any_in_typed_gen([0,0,0])
199
>>> any_in_typed_gen(VerboseGetItem([0,0,1,0,0]))
204
>>> any_in_typed_gen(VerboseGetItem([0,0,0,0,0]))
214
return any(x for x in seq)
217
@cython.test_assert_path_exists(
219
"//InlinedGeneratorExpressionNode",
220
"//InlinedGeneratorExpressionNode//IfStatNode"
222
@cython.test_fail_if_path_exists(
226
def any_in_gen_builtin_name(seq):
228
>>> any_in_gen_builtin_name([0,1,0])
230
>>> any_in_gen_builtin_name([0,0,0])
233
>>> any_in_gen_builtin_name(VerboseGetItem([0,0,1,0,0]))
238
>>> any_in_gen_builtin_name(VerboseGetItem([0,0,0,0,0]))
247
return any(type for type in seq)
250
@cython.test_assert_path_exists(
252
"//InlinedGeneratorExpressionNode",
253
"//InlinedGeneratorExpressionNode//IfStatNode"
255
@cython.test_fail_if_path_exists(
258
# "//IfStatNode//CoerceToBooleanNode"
260
def any_in_double_gen(seq):
262
>>> any(x for L in [[0,0,0],[0,0,1],[0,0,0]] for x in L)
264
>>> any_in_double_gen([[0,0,0],[0,0,1],[0,0,0]])
267
>>> any(x for L in [[0,0,0],[0,0,0],[0,0,0]] for x in L)
269
>>> any_in_double_gen([[0,0,0],[0,0,0],[0,0,0]])
272
>>> any_in_double_gen([VerboseGetItem([0,0,0]), VerboseGetItem([0,0,1,0,0])])
281
>>> any_in_double_gen([VerboseGetItem([0,0,0]),VerboseGetItem([0,0]),VerboseGetItem([0,0,0])])
296
return any(x for L in seq for x in L)