cython

Форк
0
/
cdef_members_T517.pyx 
130 строк · 2.5 Кб
1
# ticket: t517
2
#cython: embedsignature=True
3

4
__doc__ = u"""
5
>>> a = A()
6
>>> a.h = 7
7
>>> a.i = 127
8
>>> a.l = 255
9
>>> a.q = 255
10
>>> a.f = 1.0/2.0
11
>>> a.d = 1/2.0 + 1/4.0
12
>>> a.g = 1/2.0 + 1/4.0 + 1/8.0
13
>>> a.Zf = 1+2j
14
>>> a.Zd = 3+4j
15
>>> a.Zg = 5+6j
16

17
>>> a.h, a.i, a.l
18
(7, 127, 255)
19
>>> a.ro_h, a.ro_i, a.ro_l
20
(7, 127, 255)
21
>>> a.f, a.d, a.g
22
(0.5, 0.75, 0.875)
23
>>> a.ro_f, a.ro_d, a.ro_g
24
(0.5, 0.75, 0.875)
25
>>> a.Zf, a.Zd, a.Zg
26
((1+2j), (3+4j), (5+6j))
27
>>> a.ro_Zf, a.ro_Zd, a.ro_Zg
28
((1+2j), (3+4j), (5+6j))
29

30
>>> b = B()
31
>>> b.a0 #doctest: +ELLIPSIS
32
Traceback (most recent call last):
33
AttributeError: ...
34

35
>>> b.b0 #doctest: +ELLIPSIS
36
Traceback (most recent call last):
37
AttributeError: ...
38

39
>>> b.c0 #doctest: +ELLIPSIS
40
Traceback (most recent call last):
41
AttributeError: ...
42

43
>>> isinstance(b.a1, type(None))
44
True
45
>>> isinstance(b.a2, type(None))
46
True
47
>>> isinstance(b.b1, list)
48
True
49
>>> isinstance(b.b2, list)
50
True
51
>>> isinstance(b.c1, A)
52
True
53
>>> isinstance(b.c2, A)
54
True
55

56
>>> b.a1 = a
57
>>> b.a1 is not b.a2
58
True
59

60
>>> try: b.b1 = 1
61
... except (TypeError, AttributeError): pass
62

63
>>> try: b.c1 = 1
64
... except (TypeError, AttributeError): pass
65

66
>>> try: b.a2 = None
67
... except (TypeError, AttributeError): pass
68

69
>>> try: b.b2 = []
70
... except (TypeError, AttributeError): pass
71

72
>>> try: b.c2 = A()
73
... except (TypeError, AttributeError): pass
74
"""
75

76

77
cdef class A:
78

79
    cdef public short h
80
    cdef public int i
81
    cdef public long l
82
    cdef public long long q
83
    cdef public float f
84
    cdef public double d
85
    cdef public long double g
86
    cdef public float complex Zf
87
    cdef public double complex Zd
88
    cdef public long double complex Zg
89

90
    cdef readonly short ro_h
91
    cdef readonly int ro_i
92
    cdef readonly long ro_l
93
    cdef readonly long long ro_q
94
    cdef readonly float ro_f
95
    cdef readonly double ro_d
96
    cdef readonly long double ro_g
97
    cdef readonly float complex ro_Zf
98
    cdef readonly double complex ro_Zd
99
    cdef readonly long double complex ro_Zg
100

101
    def __cinit__(self):
102
        self.ro_h = 7
103
        self.ro_i = 127
104
        self.ro_l = 255
105
        self.ro_q = 255
106
        self.ro_f = 1.0/2.0
107
        self.ro_d = 1/2.0 + 1/4.0
108
        self.ro_g = 1/2.0 + 1/4.0 + 1/8.0
109
        self.ro_Zf = 1+2j
110
        self.ro_Zd = 3+4j
111
        self.ro_Zg = 5+6j
112

113

114
cdef class B:
115

116
    cdef object a0
117
    cdef public object a1
118
    cdef readonly object a2
119

120
    cdef list b0
121
    cdef public list b1
122
    cdef readonly list b2
123

124
    cdef A c0
125
    cdef public A c1
126
    cdef readonly A c2
127

128
    def __cinit__(self):
129
        self.b0 = self.b1 = self.b2 = []
130
        self.c0 = self.c1 = self.c2 = A()
131

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

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

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

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