Cython has moved to github.

cython-devel

view tests/run/contains_T455.pyx @ 2673:2266c6948c98

implementation of 'not in' is broken (ticket #455)
author Lisandro Dalcin <dalcinl@gmail.com>
date Wed Nov 11 13:11:31 2009 -0200 (2 years ago)
parents
children 1bb2be2073e8
line source
1 def in_sequence(x, seq):
2 """
3 >>> in_sequence(1, [])
4 False
5 >>> in_sequence(1, ())
6 False
7 >>> in_sequence(1, {})
8 False
9 >>> in_sequence(1, [1])
10 True
11 >>> in_sequence(1, (1,))
12 True
13 >>> in_sequence(1, {1:None})
14 True
16 >>> in_sequence(1, None)
17 Traceback (most recent call last):
18 ...
19 TypeError: argument of type 'NoneType' is not iterable
21 >>> in_sequence(1, 1)
22 Traceback (most recent call last):
23 ...
24 TypeError: argument of type 'int' is not iterable
25 """
26 return x in seq
28 def not_in_sequence(x, seq):
29 """
30 >>> not_in_sequence(1, [])
31 True
32 >>> not_in_sequence(1, ())
33 True
34 >>> not_in_sequence(1, {})
35 True
36 >>> not_in_sequence(1, [1])
37 False
38 >>> not_in_sequence(1, (1,))
39 False
40 >>> not_in_sequence(1, {1:None})
41 False
43 >>> not_in_sequence(1, None)
44 Traceback (most recent call last):
45 ...
46 TypeError: argument of type 'NoneType' is not iterable
48 >>> not_in_sequence(1, 1)
49 Traceback (most recent call last):
50 ...
51 TypeError: argument of type 'int' is not iterable
52 """
53 return x not in seq
56 def in_dict(k, dict dct):
57 """
58 >>> in_dict(1, {})
59 False
60 >>> in_dict(1, {1:None})
61 True
63 >>> in_dict(1, None)
64 Traceback (most recent call last):
65 ...
66 TypeError: 'NoneType' object is not iterable
67 """
68 return k in dct
70 def not_in_dict(k, dict dct):
71 """
72 >>> not_in_dict(1, {})
73 True
74 >>> not_in_dict(1, {1:None})
75 False
77 >>> not_in_dict(1, None)
78 Traceback (most recent call last):
79 ...
80 TypeError: 'NoneType' object is not iterable
81 """
82 return k not in dct