Cython has moved to github.
cython-devel
view tests/run/__getattribute_subclasses__.pyx @ 1622:4f0327bdebc9
test for temp allocation bug in call
| author | Robert Bradshaw <robertwb@math.washington.edu> |
|---|---|
| date | Sat Jan 17 01:25:34 2009 -0800 (3 years ago) |
| parents | 6309e21af543 |
| children | 1dadfbd04642 |
line source
1 __doc__ = u"""
2 __getattribute__ and __getattr__ special methods and subclasses.
4 getattr does not override members.
5 >>> a = getattr_boring()
6 >>> a.boring_member
7 10
8 >>> print(a.resolved_by)
9 getattr_boring
11 getattribute does.
12 >>> a = getattribute_boring()
13 >>> a.boring_member
14 Traceback (most recent call last):
15 AttributeError
16 >>> print(a.resolved_by)
17 getattribute_boring
19 Is inherited.
20 >>> a = boring_boring_getattribute()
21 >>> a.boring_getattribute_member
22 Traceback (most recent call last):
23 AttributeError
24 >>> a.boring_boring_getattribute_member
25 Traceback (most recent call last):
26 AttributeError
27 >>> print(a.resolved_by)
28 _getattribute
30 __getattribute__ is always tried first, then __getattr__, regardless of where
31 in the inheritance hiarchy they came from.
32 >>> a = getattribute_boring_boring_getattr()
33 >>> a.foo
34 Traceback (most recent call last):
35 AttributeError
36 >>> print(a.resolved_by)
37 getattribute_boring_boring_getattr
38 >>> a.getattribute_boring_boring_getattr
39 True
40 >>> a._getattr
41 True
43 >>> a = getattr_boring_boring_getattribute()
44 >>> a.foo
45 Traceback (most recent call last):
46 AttributeError
47 >>> print(a.resolved_by)
48 _getattribute
49 >>> a.getattr_boring_boring_getattribute
50 True
51 >>> a._getattribute
52 True
54 """
56 cdef class boring:
57 cdef readonly int boring_member
58 def __init__(self):
59 self.boring_member = 10
61 cdef class getattr_boring(boring):
62 def __getattr__(self,n):
63 if n == u'resolved_by':
64 return u'getattr_boring'
65 elif n == u'getattr_boring':
66 return True
67 else:
68 raise AttributeError
70 cdef class getattribute_boring(boring):
71 def __getattribute__(self,n):
72 if n == u'resolved_by':
73 return u'getattribute_boring'
74 elif n == u'getattribute_boring':
75 return True
76 else:
77 raise AttributeError
79 cdef class _getattr:
80 def __getattr__(self,n):
81 if n == u'resolved_by':
82 return u'_getattr'
83 elif n == u'_getattr':
84 return True
85 else:
86 raise AttributeError
88 cdef class _getattribute(boring):
89 def __getattribute__(self,n):
90 if n == u'resolved_by':
91 return u'_getattribute'
92 elif n == u'_getattribute':
93 return True
94 else:
95 raise AttributeError
97 cdef class boring_getattribute(_getattribute):
98 cdef readonly int boring_getattribute_member
100 cdef class boring_boring_getattribute(boring_getattribute):
101 cdef readonly int boring_boring_getattribute_member
103 cdef class boring_getattr(_getattr):
104 cdef readonly int boring_getattr_member
106 cdef class boring_boring_getattr(boring_getattr):
107 cdef readonly int boring_boring_getattr_member
109 cdef class getattribute_boring_boring_getattr(boring_boring_getattr):
110 def __getattribute__(self,n):
111 if n == u'resolved_by':
112 return u'getattribute_boring_boring_getattr'
113 elif n == u'getattribute_boring_boring_getattr':
114 return True
115 else:
116 raise AttributeError
118 cdef class getattr_boring_boring_getattribute(boring_boring_getattribute):
119 def __getattr__(self,n):
120 if n == u'resolved_by':
121 return u'getattr_boring_boring_getattribute'
122 elif n == u'getattr_boring_boring_getattribute':
123 return True
124 else:
125 raise AttributeError
