+++ /dev/null
-cdef int i
-cdef x
-
-def f(a):
- global i, x
- i = 42
- x = a
+++ /dev/null
-x = "foo".join(y)
-
+++ /dev/null
-cdef class Spam:
-
- cdef int tons
-
- cdef void add_tons(self, int x):
- self.tons = self.tons + x
-
- cdef void eat(self):
- self.tons = 0
-
-
-cdef class SuperSpam(Spam):
-
- cdef void add_tons(self, int x):
- self.tons = self.tons + 2 * x
+++ /dev/null
-spam = "ftang"
+++ /dev/null
-include "filenames.pxi"
-
-foo = 42
-
+++ /dev/null
-cdef class Parrot:
-
- cdef void describe(self):
- pass
-
-
-cdef class Norwegian(Parrot):
-
- cdef void describe(self):
- Parrot.describe(self)
+++ /dev/null
-DEF STUFF = "Spam"
-
-cdef void f():
- IF STUFF == "Spam":
- print "It works!"
- ELSE:
- print "Doesn't work"
+++ /dev/null
-cdef int i, j, k
-i = 17; j = 42; k = i * j
-if j > k: i = 88
-else: i = 99; j = k
+++ /dev/null
-def test():
- cdef int a,b
- foo=(55,66)
- a,b=foo
cdef char *ptr1, *ptr2
cdef int *ptr3
bool = int1 == int2
- bool = int1 <> int2
bool = int1 != int2
bool = float1 == float2
bool = ptr1 == ptr2
def __add__(int x, float y):
pass
-
- def __getslice__(self, i, j):
- pass
-
- def __setslice__(self, Py_ssize_t i, float j, x):
- pass
cdef class Swallow:
pass
def __delitem__(self, i):
pass
-
- def __delslice__(self, i, j):
- pass
def __delattr__(self, n):
pass
def __setitem__(self, i, x):
pass
-
- def __setslice__(self, i, j, x):
- pass
def __setattr__(self, n, x):
pass
--- /dev/null
+struct Tomato {\r PyObject_HEAD\r};\r\rstruct Bicycle{\r PyObject_HEAD\r};\r
\ No newline at end of file
+__doc__ = u"""
+>>> main()
+3.14159265358979323846
+3.14159265358979323846
+3.14159265358979323846
+"""
+
cdef extern from "math.h":
double M_PI
+__doc__ = u"""
+>>> p
+42
+"""
+
cdef enum:
spam = 42
grail = 17
cdef int i
i = spam
+p = i
--- /dev/null
+__doc__ = u"""
+>>> what()
+0 5
+>>> f(5)
+>>> what()
+42 5
+>>> f(6)
+>>> what()
+42 6
+>>> f("spam")
+>>> what()
+42 spam
+"""
+
+cdef int i = 0
+cdef x = 5
+
+def f(a):
+ global i, x
+ i = 42
+ x = a
+
+def what():
+ print i,x
--- /dev/null
+__doc__ = u"""
+>>> y
+(b'1', b'2', b'3')
+>>> x
+b'1foo2foo3'
+"""
+
+import sys
+if sys.version_info[0] < 3:
+ __doc__ = __doc__.replace(u"b'", u"'")
+
+
+y = ('1','2','3')
+
+x = 'foo'.join(y)
--- /dev/null
+__doc__ = u"""
+>>> test()
+5
+0
+20
+5
+"""
+
+cdef class Spam:
+
+ cdef int tons
+
+ cdef void add_tons(self, int x):
+ self.tons = self.tons + x
+
+ cdef void eat(self):
+ self.tons = 0
+
+ def lift(self):
+ print self.tons
+
+cdef class SuperSpam(Spam):
+
+ cdef void add_tons(self, int x):
+ self.tons = self.tons + 2 * x
+
+def test():
+ cdef Spam s
+ cdef SuperSpam ss
+ s = Spam()
+ s.eat()
+ s.add_tons(5)
+ s.lift()
+
+ ss = SuperSpam()
+ ss.eat()
+ ss.lift()
+
+ ss.add_tons(10)
+ ss.lift()
+
+ s.lift()
+__doc__ = u"""
+>>> tomato()
+42
+"""
+
cdef class Spam:
property eggs:
def __get__(self):
- pass
+ return 42
-cdef void tomato():
+def tomato():
cdef Spam spam
cdef object lettuce
+ spam = Spam()
lettuce = spam.eggs
-
+ return lettuce
--- /dev/null
+spam = u"ftang"
--- /dev/null
+__doc__ = u"""
+>>> print(spam)
+ftang
+>>> foo
+42
+"""
+
+include "filenames.pxi"
+
+foo = 42
+
--- /dev/null
+__doc__ = u"""
+>>> p = Norwegian()
+>>> p.describe()
+Norwegian
+Parrot
+"""
+
+cdef class Parrot:
+
+ cdef void _describe(self):
+ print u"Parrot"
+
+ def describe(self):
+ self._describe()
+
+cdef class Norwegian(Parrot):
+
+ cdef void _describe(self):
+ print u"Norwegian"
+ Parrot._describe(self)
--- /dev/null
+__doc__ = u"""
+>>> f()
+It works!
+"""
+
+DEF STUFF = "Spam"
+
+def f():
+ IF STUFF == "Spam":
+ print u"It works!"
+ ELSE:
+ print u"Doesn't work"
-cdef loops():
+__doc__ = u"""
+>>> loops()
+5
+"""
+
+def loops():
cdef int k
for i from 0 <= i < 5:
for j from 0 <= j < 2:
k = i + j
+ return k
+__doc__ = u"""
+>>> g()
+"""
+
cdef class Spam:
pass
cdef f(Spam s):
pass
-cdef g():
+def g():
f(None)
--- /dev/null
+__doc__ = u"""
+>>> result() == (99, 17*42, 17*42)
+True
+"""
+
+cdef int i, j, k
+i = 17; j = 42; k = i * j
+if j > k: i = 88
+else: i = 99; j = k
+
+def result():
+ return (i,j,k)
--- /dev/null
+__doc__ = u"""
+>>> test() == 55 + 66
+True
+"""
+
+
+def test():
+ cdef int a,b
+ foo=(55,66)
+ a,b=foo
+ return a + b