cython

Форк
0
/
static_methods.pyx 
108 строк · 2.3 Кб
1
cdef class A:
2
    @staticmethod
3
    def static_def(int x):
4
        """
5
        >>> A.static_def(2)
6
        ('def', 2)
7
        >>> A().static_def(2)
8
        ('def', 2)
9
        """
10
        return 'def', x
11

12
    @staticmethod
13
    cdef static_cdef(int* x):
14
        return 'cdef', x[0]
15

16
    @staticmethod
17
    cdef static_cdef2(int* x, int* y):
18
        return 'cdef2', x[0] + y[0]
19

20
    @staticmethod
21
    cdef static_cdef_untyped(a, b):
22
        return 'cdef_utyped', a, b
23

24
#     @staticmethod
25
#     cpdef static_cpdef(int x):
26
#         """
27
#         >>> A.static_def
28
#         >>> A.static_cpdef
29
#
30
#         >>> A().static_def
31
#         >>> A().static_cpdef
32
#
33
#         >>> A.static_cpdef(2)
34
#         ('cpdef', 2)
35
#         >>> A().static_cpdef(2)
36
#         ('cpdef', 2)
37
#         """
38
#         return 'cpdef', x
39

40
def call_static_def(int x):
41
    """
42
    >>> call_static_def(2)
43
    ('def', 2)
44
    """
45
    return A.static_def(x)
46

47
def call_static_cdef(int x):
48
    """
49
    >>> call_static_cdef(2)
50
    ('cdef', 2)
51
    """
52
    cdef int *x_ptr = &x
53
    return A.static_cdef(x_ptr)
54

55
def call_static_cdef2(int x, int y):
56
    """
57
    >>> call_static_cdef2(2, 3)
58
    ('cdef2', 5)
59
    """
60
    return A.static_cdef2(&x, &y)
61

62
def call_static_list_comprehension_GH1540(int x):
63
    """
64
    >>> call_static_list_comprehension_GH1540(5)
65
    [('cdef', 5), ('cdef', 5), ('cdef', 5)]
66
    """
67
    return [A.static_cdef(&x) for _ in range(3)]
68

69
# BROKEN
70
#def call_static_cdef_untyped(a, b):
71
#    """
72
#    >>> call_static_cdef_untyped(100, None)
73
#    ('cdef_untyped', 100, None)
74
#    """
75
#    return A.static_cdef_untyped(a, b)
76

77
# UNIMPLEMENTED
78
# def call_static_cpdef(int x):
79
#     """
80
#     >>> call_static_cpdef(2)
81
#     ('cpdef', 2)
82
#     """
83
#     return A.static_cpdef(x)
84

85
cdef class FromPxd:
86
    @staticmethod
87
    cdef static_cdef(int* x):
88
        return 'pxd_cdef', x[0]
89

90
    @staticmethod
91
    cdef static_cdef_with_implicit_object(obj):
92
        return obj+1
93

94
def call_static_pxd_cdef(int x):
95
    """
96
    >>> call_static_pxd_cdef(2)
97
    ('pxd_cdef', 2)
98
    """
99
    cdef int *x_ptr = &x
100
    return FromPxd.static_cdef(x_ptr)
101

102
def call_static_pxd_cdef_with_implicit_object(int x):
103
    """
104
    # https://github.com/cython/cython/issues/3174
105
    >>> call_static_pxd_cdef_with_implicit_object(2)
106
    3
107
    """
108
    return FromPxd.static_cdef_with_implicit_object(x)
109

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

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

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

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