Cython has moved to github.

cython-devel

view tests/run/decorators.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 a320e6c04422
children
line source
1 __doc__ = u"""
2 >>> f(1,2)
3 4
4 >>> f.HERE
5 1
7 >>> g(1,2)
8 5
9 >>> g.HERE
10 5
12 >>> h(1,2)
13 6
14 >>> h.HERE
15 1
16 >>> i(4)
17 3
18 >>> i.HERE
19 1
20 """
22 class wrap:
23 def __init__(self, func):
24 self.func = func
25 self.HERE = 1
26 def __call__(self, *args, **kwargs):
27 return self.func(*args, **kwargs)
29 def decorate(func):
30 try:
31 func.HERE += 1
32 except AttributeError:
33 func = wrap(func)
34 return func
36 def decorate2(a,b):
37 return decorate
39 @decorate
40 def f(a,b):
41 return a+b+1
43 @decorate
44 @decorate
45 @decorate
46 @decorate
47 @decorate
48 def g(a,b):
49 return a+b+2
51 @decorate2(1,2)
52 def h(a,b):
53 return a+b+3
55 class A:
56 def decorate(self, func):
57 return decorate(func)
60 a = A()
61 @a.decorate
62 def i(x):
63 return x - 1