1# mode: run 2# ticket: 303 3 4__doc__ = """ 5>>> try: readonly() 6... except (TypeError, AttributeError): pass 7""" 8 9 10cdef extern from "external_defs.h": 11 ctypedef float DoubleTypedef 12 ctypedef float LongDoubleTypedef 13 14cdef public DoubleTypedef global_tdef 15cdef public double global_double 16 17cdef class MyClass: 18 cdef readonly: 19 double actual_double 20 DoubleTypedef float_isreally_double 21 LongDoubleTypedef float_isreally_longdouble 22 23 def __init__(self): 24 self.actual_double = 42.0 25 self.float_isreally_double = 42.0 26 self.float_isreally_longdouble = 42.0 27 28def global_vars(x): 29 """ 30 >>> global_vars(12.0) 31 12.0 12.0 32 """ 33 global global_tdef, global_double 34 global_tdef = x 35 global_double = x 36 print global_tdef, global_double 37 38def f(): 39 """ 40 >>> f() 41 42.0 42 42.0 43 """ 44 cdef object c = MyClass() 45 print c.actual_double 46 print c.float_isreally_double 47 48def longdouble_access(): 49 """ 50 >>> longdouble_access() 51 42.0 52 """ 53 cdef object c = MyClass() 54 print c.float_isreally_longdouble 55 56 57def readonly(): 58 cdef object c = MyClass() 59 c.actual_double = 3 60