13 cdef object result = a in b
25 cdef int result = a in b
35 cdef object result = 2 in b
45 cdef int result = 2 in b
48 @cython.test_fail_if_path_exists("//SwitchStatNode")
56 cdef int result = a in [1,2,3,4]
59 @cython.test_assert_path_exists("//SwitchStatNode")
60 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
68 cdef int result = a in [1,2,3,4]
71 @cython.test_assert_path_exists("//SwitchStatNode")
72 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
80 cdef int result = a in (1,2,3,4)
83 @cython.test_assert_path_exists("//SwitchStatNode")
84 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
92 cdef int result = a in {1,2,3,4}
95 cdef bytes bytes_string = b'ab\0cde\0f\0g'
96 py_bytes_string = bytes_string
98 @cython.test_assert_path_exists("//PrimaryCmpNode")
99 @cython.test_fail_if_path_exists("//SwitchStatNode", "//BoolBinopNode")
100 def m_bytes(char a, bytes bytes_string):
102 >>> m_bytes(ord('f'), py_bytes_string)
104 >>> m_bytes(ord('X'), py_bytes_string)
106 >>> 'f'.encode('ASCII') in None # doctest: +ELLIPSIS
107 Traceback (most recent call last):
108 TypeError: ...iterable...
109 >>> m_bytes(ord('f'), None)
110 Traceback (most recent call last):
111 TypeError: argument of type 'NoneType' is not iterable
113 cdef int result = a in bytes_string
116 @cython.test_assert_path_exists("//PrimaryCmpNode")
117 @cython.test_fail_if_path_exists("//SwitchStatNode", "//BoolBinopNode")
118 def m_bytes_unsigned(unsigned char a, bytes bytes_string):
120 >>> m_bytes(ord('f'), py_bytes_string)
122 >>> m_bytes(ord('X'), py_bytes_string)
124 >>> 'f'.encode('ASCII') in None # doctest: +ELLIPSIS
125 Traceback (most recent call last):
126 TypeError: ...iterable...
127 >>> m_bytes(ord('f'), None)
128 Traceback (most recent call last):
129 TypeError: argument of type 'NoneType' is not iterable
131 cdef int result = a in bytes_string
134 @cython.test_assert_path_exists("//SwitchStatNode")
135 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
136 def m_bytes_literal(char a):
138 >>> m_bytes_literal(ord('f'))
140 >>> m_bytes_literal(ord('X'))
143 cdef int result = a in b'ab\0cde\0f\0g'
146 @cython.test_assert_path_exists("//SwitchStatNode")
147 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
148 def m_bytes_literal_unsigned(unsigned char a):
150 >>> m_bytes_literal(ord('f'))
152 >>> m_bytes_literal(ord('X'))
155 cdef int result = a in b'ab\0cde\0f\0g'
158 cdef unicode unicode_string = u'abc\0defg\u1234\uF8D2'
159 py_unicode_string = unicode_string
161 @cython.test_assert_path_exists("//PrimaryCmpNode")
162 @cython.test_fail_if_path_exists("//SwitchStatNode", "//BoolBinopNode")
163 def m_unicode(Py_UNICODE a, unicode unicode_string):
165 >>> m_unicode(ord('f'), py_unicode_string)
167 >>> m_unicode(ord('X'), py_unicode_string)
169 >>> m_unicode(ord(py_klingon_character), py_unicode_string)
172 >>> 'f' in None # doctest: +ELLIPSIS
173 Traceback (most recent call last):
174 TypeError: ...iterable...
175 >>> m_unicode(ord('f'), None)
176 Traceback (most recent call last):
177 TypeError: argument of type 'NoneType' is not iterable
179 cdef int result = a in unicode_string
182 cdef unicode klingon_character = u'\uF8D2'
183 py_klingon_character = klingon_character
185 @cython.test_assert_path_exists("//SwitchStatNode")
186 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
187 def m_unicode_literal(Py_UNICODE a):
189 >>> m_unicode_literal(ord('f'))
191 >>> m_unicode_literal(ord('X'))
193 >>> m_unicode_literal(ord(py_klingon_character))
196 cdef int result = a in u'abc\0defg\u1234\uF8D2'
199 cdef unicode wide_unicode_character = u'\U0010FEDC'
200 py_wide_unicode_character = wide_unicode_character
201 wide_unicode_character_surrogate1 = 0xDBFF
202 wide_unicode_character_surrogate2 = 0xDEDC
204 @cython.test_fail_if_path_exists("//SwitchStatNode")
205 @cython.test_assert_path_exists("//PrimaryCmpNode")
206 def m_wide_unicode_literal(Py_UNICODE a):
208 >>> m_unicode_literal(ord('f'))
210 >>> m_unicode_literal(ord('X'))
213 >>> if sys.maxunicode == 65535:
214 ... m_wide_unicode_literal(wide_unicode_character_surrogate1)
215 ... m_wide_unicode_literal(wide_unicode_character_surrogate2)
217 ... m_wide_unicode_literal(ord(py_wide_unicode_character))
222 cdef int result = a in u'abc\0defg\u1234\uF8D2\U0010FEDC'
225 @cython.test_assert_path_exists("//SwitchStatNode")
226 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
227 def conditional_int(int a):
229 >>> conditional_int(1)
231 >>> conditional_int(0)
233 >>> conditional_int(5)
236 return 1 if a in (1,2,3,4) else 2
238 @cython.test_assert_path_exists("//SwitchStatNode")
239 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
240 def conditional_object(int a):
242 >>> conditional_object(1)
244 >>> conditional_object(0)
246 >>> conditional_object(5)
249 return 1 if a in (1,2,3,4) else '2'
251 @cython.test_assert_path_exists("//SwitchStatNode")
252 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
253 def conditional_bytes(char a):
255 >>> conditional_bytes(ord('a'))
257 >>> conditional_bytes(ord('X'))
259 >>> conditional_bytes(0)
262 return 1 if a in b'abc' else '2'
264 @cython.test_assert_path_exists("//SwitchStatNode")
265 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
266 def conditional_unicode(Py_UNICODE a):
268 >>> conditional_unicode(ord('a'))
270 >>> conditional_unicode(ord('X'))
272 >>> conditional_unicode(0)
275 return 1 if a in u'abc' else '2'
277 @cython.test_assert_path_exists("//SwitchStatNode")
278 @cython.test_fail_if_path_exists("//BoolBinopNode", "//PrimaryCmpNode")
279 def conditional_none(int a):
281 >>> conditional_none(1)
282 >>> conditional_none(0)
284 >>> conditional_none(5)
287 return None if a in {1,2,3,4} else 1
296 cdef int result = a.lower() in [u'a *',u'b *',u'c *',u'd *']
306 cdef dict d = {u'a': 1, u'b': 2}
307 cdef int result = a in d
313 Traceback (most recent call last):
314 TypeError: 'NoneType' object is not iterable
316 >>> l2 = [l[1:],l[:-1],l]
321 cdef int result = a in d # should fail with a TypeError
329 cdef object l = [1,2,3,4]
330 cdef object l2 = [l[1:],l[:-1],l]
331 cdef int result = a in l in l2
339 cdef int result = a in [1,2,3,4] in [[1,2,3],[2,3,4],[1,2,3,4]]