Remove trailing whitespace.
[cython.git] / tests / run / list_pop.pyx
1 cimport cython
2
3 class A:
4     def pop(self, *args):
5         print args
6         return None
7
8
9 @cython.test_assert_path_exists('//PythonCapiCallNode')
10 @cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode')
11 def simple_pop(L):
12     """
13     >>> L = list(range(10))
14     >>> simple_pop(L)
15     9
16     >>> simple_pop(L)
17     8
18     >>> L
19     [0, 1, 2, 3, 4, 5, 6, 7]
20     >>> while L:
21     ...    _ = simple_pop(L)
22
23     >>> L
24     []
25     >>> simple_pop(L)
26     Traceback (most recent call last):
27     ...
28     IndexError: pop from empty list
29
30     >>> simple_pop(A())
31     ()
32     """
33     return L.pop()
34
35 @cython.test_assert_path_exists('//PythonCapiCallNode')
36 @cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode')
37 def simple_pop_typed(list L):
38     """
39     >>> L = list(range(10))
40     >>> simple_pop_typed(L)
41     9
42     >>> simple_pop_typed(L)
43     8
44     >>> L
45     [0, 1, 2, 3, 4, 5, 6, 7]
46     >>> while L:
47     ...    _ = simple_pop_typed(L)
48
49     >>> L
50     []
51     >>> simple_pop_typed(L)
52     Traceback (most recent call last):
53     ...
54     IndexError: pop from empty list
55     """
56     return L.pop()
57
58
59 @cython.test_assert_path_exists('//PythonCapiCallNode')
60 @cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode')
61 def index_pop(L, int i):
62     """
63     >>> L = list(range(10))
64     >>> index_pop(L, 2)
65     2
66     >>> index_pop(L, -2)
67     8
68     >>> L
69     [0, 1, 3, 4, 5, 6, 7, 9]
70     >>> index_pop(L, 100)
71     Traceback (most recent call last):
72     ...
73     IndexError: pop index out of range
74     >>> index_pop(L, -100)
75     Traceback (most recent call last):
76     ...
77     IndexError: pop index out of range
78
79     >>> while L:
80     ...    _ = index_pop(L, 0)
81
82     >>> L
83     []
84
85     >>> index_pop(L, 0)
86     Traceback (most recent call last):
87     ...
88     IndexError: pop from empty list
89
90     >>> index_pop(A(), 3)
91     (3,)
92     """
93     return L.pop(i)
94
95 @cython.test_assert_path_exists('//PythonCapiCallNode')
96 @cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode')
97 def index_pop_typed(list L, int i):
98     """
99     >>> L = list(range(10))
100     >>> index_pop_typed(L, 2)
101     2
102     >>> index_pop_typed(L, -2)
103     8
104     >>> L
105     [0, 1, 3, 4, 5, 6, 7, 9]
106     >>> index_pop_typed(L, 100)
107     Traceback (most recent call last):
108     ...
109     IndexError: pop index out of range
110     >>> index_pop_typed(L, -100)
111     Traceback (most recent call last):
112     ...
113     IndexError: pop index out of range
114
115     >>> while L:
116     ...    _ = index_pop_typed(L, 0)
117
118     >>> L
119     []
120
121     >>> index_pop_typed(L, 0)
122     Traceback (most recent call last):
123     ...
124     IndexError: pop from empty list
125     """
126     return L.pop(i)
127
128
129 @cython.test_fail_if_path_exists('//PythonCapiCallNode')
130 def crazy_pop(L):
131     """
132     >>> crazy_pop(list(range(10)))    # doctest: +ELLIPSIS
133     Traceback (most recent call last):
134     TypeError: pop... at most 1 argument...3...
135     >>> crazy_pop(A())
136     (1, 2, 3)
137     """
138     return L.pop(1, 2, 3)