Cython has moved to github.

cython-devel

view tests/run/__getattribute__.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 ea31d3be11ce
line source
1 __doc__ = u"""
2 __getattribute__ and __getattr__ special methods for a single class.
4 >>> a = just_getattribute()
5 >>> a.bar
6 'bar'
7 >>> a.invalid
8 Traceback (most recent call last):
9 AttributeError
11 >>> a = just_getattr()
12 >>> a.foo
13 10
14 >>> a.bar
15 'bar'
16 >>> a.invalid
17 Traceback (most recent call last):
18 AttributeError
20 >>> a = both()
21 >>> a.foo
22 10
23 >>> a.bar
24 'bar'
25 >>> a.invalid
26 Traceback (most recent call last):
27 AttributeError
28 """
30 cdef class just_getattribute:
31 def __getattribute__(self,n):
32 if n == u'bar':
33 return n
34 else:
35 raise AttributeError
37 cdef class just_getattr:
38 cdef readonly int foo
39 def __init__(self):
40 self.foo = 10
41 def __getattr__(self,n):
42 if n == u'bar':
43 return n
44 else:
45 raise AttributeError
47 cdef class both:
48 cdef readonly int foo
49 def __init__(self):
50 self.foo = 10
51 def __getattribute__(self,n):
52 if n == u'foo':
53 return self.foo
54 else:
55 raise AttributeError
56 def __getattr__(self,n):
57 if n == u'bar':
58 return n
59 else:
60 raise AttributeError