Cython has moved to github.

cython-devel

view tests/run/cdef_classmethod.pyx @ 2744:25af3c07d7c3

minor refactoring; fix handling first argument in classmethods; fix ticket #462: allow method(*args) in cdef classes
author Stefan Behnel <scoder@users.berlios.de>
date Sat Dec 05 23:39:57 2009 +0100 (2 years ago)
parents
children
line source
2 cimport cython
4 cdef class cclass:
6 @classmethod
7 def test0(cls):
8 """
9 >>> cclass.test0()
10 'type object'
11 """
12 return cython.typeof(cls)
14 @classmethod
15 def test0_args(*args):
16 """
17 >>> cclass.test0_args(1,2,3)
18 ('Python object', (1, 2, 3))
19 """
20 return cython.typeof(args[0]), args[1:]
22 @classmethod
23 def test1(cls, arg):
24 """
25 >>> cclass.test1(1)
26 ('type object', 1)
27 """
28 return cython.typeof(cls), arg
30 @classmethod
31 def test2(cls, arg1, arg2):
32 """
33 >>> cclass.test2(1,2)
34 ('type object', 1, 2)
35 """
36 return cython.typeof(cls), arg1, arg2
38 @classmethod
39 def test1_args(cls, *args):
40 """
41 >>> cclass.test1_args(1,2,3)
42 ('type object', (1, 2, 3))
43 """
44 return cython.typeof(cls), args
46 @classmethod
47 def test2_args(cls, arg, *args):
48 """
49 >>> cclass.test2_args(1,2,3)
50 ('type object', 1, (2, 3))
51 """
52 return cython.typeof(cls), arg, args
54 @classmethod
55 def test0_args_kwargs(*args, **kwargs):
56 """
57 >>> cclass.test0_args_kwargs(1,2,3)
58 ('Python object', (1, 2, 3), {})
59 """
60 return cython.typeof(args[0]), args[1:], kwargs
62 @classmethod
63 def test1_args_kwargs(cls, *args, **kwargs):
64 """
65 >>> cclass.test1_args_kwargs(1,2,3)
66 ('type object', (1, 2, 3), {})
67 """
68 return cython.typeof(cls), args, kwargs
70 @classmethod
71 def test2_args_kwargs(cls, arg, *args, **kwargs):
72 """
73 >>> cclass.test2_args_kwargs(1,2,3)
74 ('type object', 1, (2, 3), {})
75 """
76 return cython.typeof(cls), arg, args, kwargs