cython
1# mode: run
2# tag: py3k_super
3
4class A(object):
5def method(self):
6return 1
7
8@classmethod
9def class_method(cls):
10return 2
11
12@staticmethod
13def static_method():
14return 3
15
16def generator_test(self):
17return [1, 2, 3]
18
19
20class B(A):
21"""
22>>> obj = B()
23>>> obj.method()
241
25>>> B.class_method()
262
27>>> B.static_method(obj)
283
29>>> list(obj.generator_test())
30[1, 2, 3]
31"""
32def method(self):
33return super(B, self).method()
34
35@classmethod
36def class_method(cls):
37return super(B, cls).class_method()
38
39@staticmethod
40def static_method(instance):
41return super(B, instance).static_method()
42
43def generator_test(self):
44for i in super(B, self).generator_test():
45yield i
46
47
48cdef class CClassBase(object):
49def method(self):
50return 'def'
51cpdef method_cp(self):
52return 'cpdef'
53
54# cdef method_c(self):
55# return 'cdef'
56# def call_method_c(self):
57# return self.method_c()
58
59cdef class CClassSub(CClassBase):
60"""
61>>> CClassSub().method()
62'def'
63>>> CClassSub().method_cp()
64'cpdef'
65"""
66# >>> CClassSub().call_method_c()
67# 'cdef'
68
69def method(self):
70return super(CClassSub, self).method()
71cpdef method_cp(self):
72return super(CClassSub, self).method_cp()
73
74# cdef method_c(self):
75# return super(CClassSub, self).method_c()
76
77cdef class Base(object):
78"""
79>>> Base().method()
80'Base'
81>>> Base.method(Base())
82'Base'
83"""
84cpdef method(self):
85return "Base"
86
87cdef class Sub(Base):
88"""
89>>> Sub().method()
90'Sub'
91>>> Sub.method(Sub())
92'Sub'
93>>> Base.method(Sub())
94'Base'
95"""
96cpdef method(self):
97return "Sub"
98