cython
1cimport cython
2
3cdef class CBase(object):
4cdef int a
5cdef c_method(self):
6return "CBase"
7cpdef cpdef_method(self):
8return "CBase"
9
10class PyBase(object):
11def py_method(self):
12return "PyBase"
13
14@cython.binding(True)
15cdef class BothBound(CBase, PyBase):
16cdef dict __dict__
17"""
18>>> b = Both()
19>>> b.py_method()
20'PyBase'
21>>> b.cp_method()
22'Both'
23>>> b.call_c_method()
24'Both'
25
26>>> isinstance(b, CBase)
27True
28>>> isinstance(b, PyBase)
29True
30"""
31cdef c_method(self):
32return "Both"
33cpdef cp_method(self):
34return "Both"
35def call_c_method(self):
36return self.c_method()
37
38cdef class BothSub(BothBound):
39"""
40>>> b = BothSub()
41>>> b.py_method()
42'PyBase'
43>>> b.cp_method()
44'Both'
45>>> b.call_c_method()
46'Both'
47"""
48pass
49
50@cython.binding(False)
51cdef class BothUnbound(CBase, PyBase):
52cdef dict __dict__
53"""
54>>> b = Both()
55>>> b.py_method()
56'PyBase'
57>>> b.cp_method()
58'Both'
59>>> b.call_c_method()
60'Both'
61
62>>> isinstance(b, CBase)
63True
64>>> isinstance(b, PyBase)
65True
66"""
67cdef c_method(self):
68return "Both"
69cpdef cp_method(self):
70return "Both"
71def call_c_method(self):
72return self.c_method()
73