cython

Форк
0
/
cdef_multiple_inheritance.pyx 
72 строки · 1.3 Кб
1
cimport cython
2

3
cdef class CBase(object):
4
    cdef int a
5
    cdef c_method(self):
6
        return "CBase"
7
    cpdef cpdef_method(self):
8
        return "CBase"
9

10
class PyBase(object):
11
    def py_method(self):
12
        return "PyBase"
13

14
@cython.binding(True)
15
cdef class BothBound(CBase, PyBase):
16
    cdef 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)
27
    True
28
    >>> isinstance(b, PyBase)
29
    True
30
    """
31
    cdef c_method(self):
32
        return "Both"
33
    cpdef cp_method(self):
34
        return "Both"
35
    def call_c_method(self):
36
        return self.c_method()
37

38
cdef 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
    """
48
    pass
49

50
@cython.binding(False)
51
cdef class BothUnbound(CBase, PyBase):
52
    cdef 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)
63
    True
64
    >>> isinstance(b, PyBase)
65
    True
66
    """
67
    cdef c_method(self):
68
        return "Both"
69
    cpdef cp_method(self):
70
        return "Both"
71
    def call_c_method(self):
72
        return self.c_method()
73

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.