1# ticket: 517 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 32Traceback (most recent call last): 33AttributeError: ... 34 35>>> b.b0 #doctest: +ELLIPSIS 36Traceback (most recent call last): 37AttributeError: ... 38 39>>> b.c0 #doctest: +ELLIPSIS 40Traceback (most recent call last): 41AttributeError: ... 42 43>>> isinstance(b.a1, type(None)) 44True 45>>> isinstance(b.a2, type(None)) 46True 47>>> isinstance(b.b1, list) 48True 49>>> isinstance(b.b2, list) 50True 51>>> isinstance(b.c1, A) 52True 53>>> isinstance(b.c2, A) 54True 55 56>>> b.a1 = a 57>>> b.a1 is not b.a2 58True 59 60TYPE_FIXES_REQUIRED: 61 62>>> try: b.b1 = 1 63... except (TypeError, AttributeError): pass 64 65>>> try: b.c1 = 1 66... except (TypeError, AttributeError): pass 67 68>>> try: b.a2 = None 69... except (TypeError, AttributeError): pass 70 71>>> try: b.b2 = [] 72... except (TypeError, AttributeError): pass 73 74>>> try: b.c2 = A() 75... except (TypeError, AttributeError): pass 76""" 77 78import sys 79if sys.version_info < (2,5): 80 __doc__ = (__doc__.split('TYPE_FIXES_REQUIRED')[0] + 81 __doc__.split('TYPE_FIXES_REQUIRED')[1].replace('\nAttributeError: ...', '\nTypeError: ...')) 82 83 84cdef class A: 85 86 cdef public short h 87 cdef public int i 88 cdef public long l 89 cdef public long long q 90 cdef public float f 91 cdef public double d 92 cdef public long double g 93 cdef public float complex Zf 94 cdef public double complex Zd 95 cdef public long double complex Zg 96 97 cdef readonly short ro_h 98 cdef readonly int ro_i 99 cdef readonly long ro_l 100 cdef readonly long long ro_q 101 cdef readonly float ro_f 102 cdef readonly double ro_d 103 cdef readonly long double ro_g 104 cdef readonly float complex ro_Zf 105 cdef readonly double complex ro_Zd 106 cdef readonly long double complex ro_Zg 107 108 def __cinit__(self): 109 self.ro_h = 7 110 self.ro_i = 127 111 self.ro_l = 255 112 self.ro_q = 255 113 self.ro_f = 1.0/2.0 114 self.ro_d = 1/2.0 + 1/4.0 115 self.ro_g = 1/2.0 + 1/4.0 + 1/8.0 116 self.ro_Zf = 1+2j 117 self.ro_Zd = 3+4j 118 self.ro_Zg = 5+6j 119 120 121cdef class B: 122 123 cdef object a0 124 cdef public object a1 125 cdef readonly object a2 126 127 cdef list b0 128 cdef public list b1 129 cdef readonly list b2 130 131 cdef A c0 132 cdef public A c1 133 cdef readonly A c2 134 135 def __cinit__(self): 136 self.b0 = self.b1 = self.b2 = [] 137 self.c0 = self.c1 = self.c2 = A() 138