Cython has moved to github.
cython-devel
view tests/run/cdef_members_T517.pyx @ 3091:1a2e04bc1395
remove dependency on structmember.h
| author | Lisandro Dalcin <dalcinl@gmail.com> |
|---|---|
| date | Thu Mar 11 17:21:13 2010 -0300 (2 years ago) |
| parents | |
| children | 3030875713b0 |
line source
1 #cython: embedsignature=True
2 __doc__ = u"""
3 >>> a = A()
4 >>> a.h = 7
5 >>> a.i = 127
6 >>> a.l = 255
7 >>> a.q = 255
8 >>> a.f = 1.0/2.0
9 >>> a.d = 1/2.0 + 1/4.0
10 >>> a.g = 1/2.0 + 1/4.0 + 1/8.0
11 >>> a.Zf = 1+2j
12 >>> a.Zd = 3+4j
13 >>> a.Zg = 5+6j
15 >>> a.h, a.i, a.l
16 (7, 127, 255)
17 >>> a.ro_h, a.ro_i, a.ro_l
18 (7, 127, 255)
19 >>> a.f, a.d, a.g
20 (0.5, 0.75, 0.875)
21 >>> a.ro_f, a.ro_d, a.ro_g
22 (0.5, 0.75, 0.875)
23 >>> a.Zf, a.Zd, a.Zg
24 ((1+2j), (3+4j), (5+6j))
25 >>> a.ro_Zf, a.ro_Zd, a.ro_Zg
26 ((1+2j), (3+4j), (5+6j))
28 >>> b = B()
29 >>> b.a0 #doctest: +ELLIPSIS
30 Traceback (most recent call last):
31 ...
32 AttributeError: ...
33 >>> b.b0 #doctest: +ELLIPSIS
34 Traceback (most recent call last):
35 ...
36 AttributeError: ...
37 >>> b.c0 #doctest: +ELLIPSIS
38 Traceback (most recent call last):
39 ...
40 AttributeError: ...
42 >>> isinstance(b.a1, type(None))
43 True
44 >>> isinstance(b.a2, type(None))
45 True
46 >>> isinstance(b.b1, list)
47 True
48 >>> isinstance(b.b2, list)
49 True
50 >>> isinstance(b.c1, A)
51 True
52 >>> isinstance(b.c2, A)
53 True
55 >>> b.a1 = a
56 >>> b.a1 is not b.a2
57 True
59 >>> b.b1 = 1 #doctest: +ELLIPSIS
60 Traceback (most recent call last):
61 ...
62 TypeError: ...
63 >>> b.c1 = 1 #doctest: +ELLIPSIS
64 Traceback (most recent call last):
65 ...
66 TypeError: ...
67 >>> b.a2 = None #doctest: +ELLIPSIS
68 Traceback (most recent call last):
69 ...
70 AttributeError: ...
71 >>> b.b2 = [] #doctest: +ELLIPSIS
72 Traceback (most recent call last):
73 ...
74 AttributeError: ...
75 >>> b.c2 = A() #doctest: +ELLIPSIS
76 Traceback (most recent call last):
77 ...
78 AttributeError: ...
79 """
81 cdef class A:
83 cdef public short h
84 cdef public int i
85 cdef public long l
86 cdef public long long q
87 cdef public float f
88 cdef public double d
89 cdef public long double g
90 cdef public float complex Zf
91 cdef public double complex Zd
92 cdef public long double complex Zg
94 cdef readonly short ro_h
95 cdef readonly int ro_i
96 cdef readonly long ro_l
97 cdef readonly long long ro_q
98 cdef readonly float ro_f
99 cdef readonly double ro_d
100 cdef readonly long double ro_g
101 cdef readonly float complex ro_Zf
102 cdef readonly double complex ro_Zd
103 cdef readonly long double complex ro_Zg
105 def __cinit__(self):
106 self.ro_h = 7
107 self.ro_i = 127
108 self.ro_l = 255
109 self.ro_q = 255
110 self.ro_f = 1.0/2.0
111 self.ro_d = 1/2.0 + 1/4.0
112 self.ro_g = 1/2.0 + 1/4.0 + 1/8.0
113 self.ro_Zf = 1+2j
114 self.ro_Zd = 3+4j
115 self.ro_Zg = 5+6j
118 cdef class B:
120 cdef object a0
121 cdef public object a1
122 cdef readonly object a2
124 cdef list b0
125 cdef public list b1
126 cdef readonly list b2
128 cdef A c0
129 cdef public A c1
130 cdef readonly A c2
132 def __cinit__(self):
133 self.b0 = self.b1 = self.b2 = []
134 self.c0 = self.c1 = self.c2 = A()
