Cython has moved to github.

cython-devel

view tests/run/list_pop.pyx @ 2653:2e3dda4a7d23

Optimized list pop.
author Robert Bradshaw <robertwb@math.washington.edu>
date Tue Nov 03 01:01:54 2009 -0800 (2 years ago)
parents
children 8d8b46892343
line source
1 cimport cython
3 class A:
4 def pop(self, *args):
5 print args
6 return None
9 @cython.test_assert_path_exists('//PythonCapiCallNode')
10 @cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode')
11 def simple_pop(L):
12 """
13 >>> L = 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)
23 >>> L
24 []
25 >>> simple_pop(L)
26 Traceback (most recent call last):
27 ...
28 IndexError: pop from empty list
30 >>> simple_pop(A())
31 ()
32 """
33 return L.pop()
35 @cython.test_assert_path_exists('//PythonCapiCallNode')
36 @cython.test_fail_if_path_exists('//SimpleCallNode/AttributeNode')
37 def index_pop(L, int i):
38 """
39 >>> L = range(10)
40 >>> index_pop(L, 2)
41 2
42 >>> index_pop(L, -2)
43 8
44 >>> L
45 [0, 1, 3, 4, 5, 6, 7, 9]
46 >>> index_pop(L, 100)
47 Traceback (most recent call last):
48 ...
49 IndexError: pop index out of range
50 >>> index_pop(L, -100)
51 Traceback (most recent call last):
52 ...
53 IndexError: pop index out of range
55 >>> while L:
56 ... _ = index_pop(L, 0)
58 >>> L
59 []
61 >>> index_pop(L, 0)
62 Traceback (most recent call last):
63 ...
64 IndexError: pop from empty list
66 >>> index_pop(A(), 3)
67 (3,)
68 """
69 return L.pop(i)
71 @cython.test_fail_if_path_exists('//PythonCapiCallNode')
72 def crazy_pop(L):
73 """
74 >>> crazy_pop(range(10))
75 Traceback (most recent call last):
76 ...
77 TypeError: pop() takes at most 1 argument (3 given)
78 >>> crazy_pop(A())
79 (1, 2, 3)
80 """
81 return L.pop(1, 2, 3)