1class A: 2 def append(self, x): 3 print u"appending", x 4 return x 5 6class B(list): 7 def append(self, *args): 8 for arg in args: 9 list.append(self, arg) 10 11cdef class C: 12 """ 13 >>> c = C(100) 14 appending 100 15 """ 16 def __init__(self, value): 17 self.append(value) 18 cdef append(self, value): 19 print u"appending", value 20 return value 21 22def test_append(L): 23 """ 24 >>> test_append([]) 25 None 26 None 27 None 28 got error 29 [1, 2, (3, 4)] 30 >>> _ = test_append(A()) 31 appending 1 32 1 33 appending 2 34 2 35 appending (3, 4) 36 (3, 4) 37 got error 38 >>> test_append(B()) 39 None 40 None 41 None 42 None 43 [1, 2, (3, 4), 5, 6] 44 """ 45 print L.append(1) 46 print L.append(2) 47 print L.append((3,4)) 48 try: 49 print L.append(5,6) 50 except TypeError: 51 print u"got error" 52 return L 53 54 55def test_append_typed(list L not None): 56 """ 57 >>> test_append_typed([]) 58 None 59 None 60 [1, 2, (3, 4)] 61 """ 62 print L.append(1) 63 L.append(2) 64 print L.append((3,4)) 65 return L 66 67 68def append_unused_retval(L): 69 """ 70 >>> append_unused_retval([]) 71 got error 72 [1, 2, (3, 4)] 73 >>> _ = append_unused_retval(A()) 74 appending 1 75 appending 2 76 appending (3, 4) 77 got error 78 >>> append_unused_retval(B()) 79 [1, 2, (3, 4), 5, 6] 80 """ 81 L.append(1) 82 L.append(2) 83 L.append((3,4)) 84 try: 85 L.append(5,6) 86 except TypeError: 87 print u"got error" 88 return L 89 90 91def method_name(): 92 """ 93 >>> method_name() 94 'append' 95 """ 96 return [].append.__name__ 97