Commit 0d5c9ae9 authored by Stefan Behnel's avatar Stefan Behnel

collection of regression tests (based on Greg's test suite)

parent be4e6108
VERSION = 0.9.6.3
PYTHON?=python
version:
@echo "Setting version to $(VERSION)"
......@@ -10,3 +11,9 @@ clean:
@rm -f *~ */*~ */*/*~
@rm -f core */core
@(cd Demos; $(MAKE) clean)
testclean:
rm -fr BUILD
test: testclean
${PYTHON} runtests.py
#!/usr/bin/python
import os, sys, unittest, doctest
from Cython.Distutils.build_ext import build_ext
from Cython.Distutils.extension import Extension
from distutils.dist import Distribution
distutils_distro = Distribution()
TEST_DIRS = ['compile', 'run']
TEST_RUN_DIRS = ['run']
INCLUDE_DIRS = os.getenv('INCLUDE', '').split(os.pathsep)
CFLAGS = os.getenv('CFLAGS', '').split()
class TestBuilder(object):
def __init__(self, rootdir, workdir):
self.rootdir = rootdir
self.workdir = workdir
def build_suite(self):
suite = unittest.TestSuite()
for filename in os.listdir(self.rootdir):
path = os.path.join(self.rootdir, filename)
if os.path.isdir(path) and filename in TEST_DIRS:
suite.addTest(
self.handle_directory(path, filename in TEST_RUN_DIRS))
return suite
def handle_directory(self, path, run_module):
suite = unittest.TestSuite()
for filename in os.listdir(path):
if not filename.endswith(".pyx"):
continue
module = filename[:-4]
suite.addTest(
CythonCompileTestCase(path, self.workdir, module))
if run_module:
suite.addTest(
CythonRunTestCase(self.workdir, module))
return suite
class CythonCompileTestCase(unittest.TestCase):
def __init__(self, directory, workdir, module):
self.directory = directory
self.workdir = workdir
self.module = module
unittest.TestCase.__init__(self)
def shortDescription(self):
return "compiling " + self.module
def runTest(self):
self.compile(self.directory, self.module, self.workdir)
def compile(self, directory, module, workdir):
build_extension = build_ext(distutils_distro)
build_extension.include_dirs = INCLUDE_DIRS[:]
build_extension.include_dirs.append(directory)
build_extension.finalize_options()
extension = Extension(
module,
sources = [os.path.join(directory, module + '.pyx')],
extra_compile_args = CFLAGS,
pyrex_c_in_temp = 1
)
build_extension.extensions = [extension]
build_extension.build_temp = workdir
build_extension.build_lib = workdir
build_extension.pyrex_c_in_temp = 1
build_extension.run()
class CythonRunTestCase(unittest.TestCase):
def __init__(self, rootdir, module):
self.rootdir, self.module = rootdir, module
unittest.TestCase.__init__(self)
def shortDescription(self):
return "running " + self.module
def runTest(self):
self.run(self)
def run(self, result=None):
sys.path.insert(0, self.rootdir)
if result is None: result = self.defaultTestResult()
try:
try:
doctest.DocTestSuite(self.module).run(result)
except ImportError:
result.startTest(self)
result.addFailure(self, sys.exc_info())
result.stopTest(self)
except Exception:
result.startTest(self)
result.addError(self, sys.exc_info())
result.stopTest(self)
if __name__ == '__main__':
# RUN ALL TESTS!
ROOTDIR = os.path.join(os.getcwd(), os.path.dirname(sys.argv[0]), 'tests')
WORKDIR = os.path.join(os.getcwd(), 'BUILD')
if not os.path.exists(WORKDIR):
os.makedirs(WORKDIR)
tests = TestBuilder(ROOTDIR, WORKDIR)
unittest.TextTestRunner(verbosity=2).run( tests.build_suite() )
cdef enum:
spam = 42
grail = 17
cdef int i
i = spam
cdef void f1(char *argv[]):
f2(argv)
cdef void f2(char *argv[]):
pass
cdef int i
cdef x
def f(a):
global i, x
i = 42
x = a
cdef void spam():
cdef long long L
cdef unsigned long long U
cdef object x
L = x
x = L
U = x
x = U
cdef int f() except -1:
cdef object x, y, z, w
cdef int i
x = abs(y)
delattr(x, 'spam')
x = dir(y)
x = divmod(y, z)
x = getattr(y, 'spam')
i = hasattr(y, 'spam')
i = hash(y)
x = intern(y)
i = isinstance(y, z)
i = issubclass(y, z)
x = iter(y)
i = len(x)
x = open(y, z)
x = pow(y, z, w)
x = reload(y)
x = repr(y)
setattr(x, y, z)
#i = typecheck(x, y)
#i = issubtype(x, y)
x = abs
cdef void foo():
cdef int bool, int1, int2, int3, int4
cdef object obj1, obj2, obj3, obj4
obj1 = 1
obj2 = 2
obj3 = 3
obj4 = 4
bool = int1 < int2 < int3
bool = obj1 < obj2 < obj3
bool = int1 < int2 < obj3
bool = obj1 < 2 < 3
bool = obj1 < 2 < 3 < 4
bool = int1 < (int2 == int3) < int4
cdef void foo():
cdef int i1, i2
cdef char c1, c2
cdef char *p1, *p2
i1 = i2
i1 = c1
p1 = p2
obj1 = i1
i1 = obj1
p1 = obj1
p1 = "spanish inquisition"
\ No newline at end of file
cdef extern class external.Spam:
pass
cdef void foo(object x):
pass
cdef void blarg(void *y, object z):
foo(<Spam>y)
foo(<Spam>z)
cdef extern int a "c_a", b "c_b"
cdef struct foo "c_foo":
int i "c_i"
ctypedef enum blarg "c_blarg":
x "c_x"
y "c_y" = 42
cdef double spam "c_spam" (int i, float f):
cdef double d "c_d"
cdef foo *p
global b
d = spam(a, f)
b = p.i
p.i = x
p.i = y
def f():
cdef int int1, int2, int3
cdef char char1
cdef long long1, long2
cdef float float1, float2
cdef double double1
int1 = int2 * int3
int1 = int2 / int3
long1 = long2 * char1
float1 = int1 * float2
double1 = float1 * int2
DEF NO = 0
DEF YES = 1
cdef void f():
cdef int i
IF YES:
i = 1
ELIF NO:
i = 2
ELSE:
i = 3
cdef void g():
cdef int i
IF NO:
i = 1
ELIF YES:
i = 2
ELSE:
i = 3
cdef void h():
cdef int i
IF NO:
i = 1
ELIF NO:
i = 2
ELSE:
i = 3
cdef void f():
cdef unsigned long x
cdef object y
x = y
y = x
def f(a, b):
global g
del g
del a[b]
del a[b][42]
del a.spam
del a.spam.eggs
cdef void spam():
cdef object x
del x[17:42]
cdef char *s
s = r'\"HT\"'
cdef void foo():
cdef int bool, int1, int2
cdef float float1, float2
cdef char *ptr1, *ptr2
cdef int *ptr3
bool = int1 == int2
bool = int1 <> int2
bool = int1 != int2
bool = float1 == float2
bool = ptr1 == ptr2
bool = int1 == float2
bool = ptr1 is ptr2
bool = ptr1 is not ptr2
\ No newline at end of file
cdef int blarg(int i):
pass
cdef void foo():
cdef float f
cdef int i
if blarg(<int> f):
pass
cdef char *f():
raise Exception
cdef extern int spam() except -1
cdef extern void grail() except *
cdef extern char *tomato() except? NULL
cdef void eggs():
cdef int i
cdef char *p
i = spam()
grail()
p = tomato()
cdef int spam() except -1:
eggs = 42
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
cdef class Grail:
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 f(Grail g):
cdef int i
cdef Swallow s
g = x
x = g
g = i
i = g
g = s
s = g
cdef class Foo:
def __delete__(self, i):
pass
cdef class Foo:
def __get__(self, i, c):
pass
cdef class Foo:
def __set__(self, i, v):
pass
cdef extern class external.Spam [object SpamObject]:
pass
ctypedef extern class external.Grail [object Grail]:
pass
cdef extern from "food.h":
class external.Tomato [object Tomato]:
pass
class external.Bicycle [object Bicycle]:
pass
cdef class Spam:
def __getitem__(self, x):
pass
cdef class Spam:
property eggs:
"Ova"
def __get__(self):
pass
def __set__(self, x):
pass
def __del__(self):
pass
cdef class Spam:
property eggs:
def __get__(self):
pass
cdef void tomato():
cdef Spam spam
cdef object lettuce
lettuce = spam.eggs
cdef class Spam:
cdef public char c
cdef public int i
cdef public long l
cdef public unsigned char uc
cdef public unsigned int ui
cdef public unsigned long ul
cdef public float f
cdef public double d
cdef public char *s
cdef public char a[42]
cdef public object o
cdef readonly int r
cdef readonly Spam e
cdef void spam():
cdef int i, j, k
for i from 0 <= i < 10:
j = k
else:
k = j
def f(x, y):
x = y
def z(a, b, c):
f(x = 42, y = "spam")
f(*a)
f(**b)
f(x = 42, **b)
f(a, *b)
f(a, x = 42, *b, **c)
\ No newline at end of file
cdef int f(a, b, c) except -1:
d = getattr3(a, b, c)
def f():
global a,b,c,d
a = b
c = d
ctypedef enum someenum_t:
ENUMVALUE_1
ENUMVALUE_2
cdef somefunction(someenum_t val):
if val == ENUMVALUE_1:
pass
def f(obj1, obj2, obj3):
cdef int int1, int2, int3
cdef float flt1, *ptr1
cdef int array1[42]
int1 = array1[int2]
flt1 = ptr1[int2]
array1[int1] = int2
ptr1[int1] = int2
obj1 = obj2[obj3]
int1 = array1[obj3]
obj1 = obj2[int3]
obj1[obj2] = obj3
array1[obj2] = int3
obj1[int2] = obj3
obj1[obj2] = 42
\ No newline at end of file
cdef class Parrot:
cdef void describe(self):
pass
cdef class Norwegian(Parrot):
cdef void describe(self):
Parrot.describe(self)
def f():
cdef int i
global mylist
del mylist[i]
return
cdef extern from "string.h":
void memcpy(void* des, void* src, int size)
cdef void f():
cdef float f1[3]
cdef float* f2
f2 = f1 + 1
memcpy(f1, f2, 1)
ctypedef enum foo:
FOO
cdef void func():
cdef foo x
map = [FOO]
x = map[0]
DEF STUFF = "Spam"
cdef void f():
IF STUFF == "Spam":
print "It works!"
ELSE:
print "Doesn't work"
cdef void foo():
cdef int bool, int1, int2
bool = int1 < int2
bool = int1 > int2
bool = int1 <= int2
bool = int1 >= int2
cdef loops():
cdef int k
for i from 0 <= i < 5:
for j from 0 <= j < 2:
k = i + j
cdef void spam():
eggs = None
cdef class Spam:
pass
cdef f(Spam s):
pass
cdef g():
f(None)
cdef extern class external.Spam [object Spam]: pass
cdef extern class external.Eggs [object Eggs]: pass
def ham(Spam s, Eggs e not None):
pass
if x: y = 42; z = 88
def f(): return 17
cdef class Spam:
pass
cdef void foo(object blarg):
pass
cdef void xyzzy():
cdef Spam spam
foo(spam)
def f(obj1, obj2, obj3):
cdef float flt1, flt2, flt3
flt1 = flt2 ** flt3
obj1 = obj2 ** obj3
cdef extern from "math.h":
double M_PI
#cdef unsigned long int n1
#n1 = 4293858116
cdef double pi
pi = 3.14159265358979323846
def main():
#print n1
print "%.18f" % M_PI
print "%.18f" % (<float> M_PI)
print "%.18f" % pi
def f(a, b, c):
#raise
raise a
raise "spam"
raise a, b
raise "spam", 42
raise a, b, c
raise "spam", 42, c()
def f(a):
a = f
a = g
def f(a, b, c, d, e, f, g, h, i):
a = b[c:d, e:f:g, ..., h, :i:]
cdef int i, j, k
i = 17; j = 42; k = i * j
if j > k: i = 88
else: i = 99; j = k
def spam():
raise Exception
cdef int grail() except -1:
raise Exception
def tomato():
spam()
grail()
def f():
cdef int i
try:
i = 1
raise x
i = 2
else:
i = 3
raise y
i = 4
def g():
cdef int i
try:
i = 1
raise x
i = 2
except a:
i = 3
else:
i = 4
raise y
i = 5
def test():
cdef int a,b
foo=(55,66)
a,b=foo
cdef int x
x = 0xFFFFFFFF
cdef public struct Foo:
int a, b
ctypedef struct Blarg:
int c, d
ctypedef public Foo Zax
cdef public class C[type C_Type, object C_Obj]:
pass
cdef public Zax *blarg
cdef api float f(Foo *x):
pass
cdef public void g(Blarg *x):
pass
cdef public api void h(Zax *x):
pass
typedef int blarg;
cdef extern from "altet1.h":
ctypedef int blarg
cdef blarg globvar
def flub(blarg bobble):
print bobble
globvar = 0
cdef swallow
def spam(w, int x = 42, y = "grail", z = swallow):
pass
cdef enum E:
z
cdef void f():
cdef int *p
cdef void *v
cdef int a[5]
cdef int i
cdef E e
p = a
v = a
p = a + i
p = a + e
p = i + a
p = e + a
p = a - i
p = a - e
cdef enum E:
spam, eggs
cdef E f() except spam:
pass
cdef extern from "stdint.h":
ctypedef int intptr_t
cdef int _is_aligned(void *ptr):
return ((<intptr_t>ptr) & ((sizeof(int))-1)) == 0
void c_func(unsigned char pixel);
cdef extern from "belchenko2.h":
void c_func(unsigned char pixel)
def f(unsigned char pixel):
c_func(pixel)
def g(signed char pixel):
c_func(pixel)
def h(char pixel):
c_func(pixel)
def f():
x = open("foo")
cdef void f():
cdef void (*p)()
p = <void(*)()>0
(<int (*)()>p)()
cdef extern int f()
cdef extern int __stdcall g()
cdef extern int __cdecl h()
cdef extern int (__stdcall *p)()
def f(obj, int i, float f, char *s1, char s2[]):
pass
\ No newline at end of file
cdef extern from *:
int spam
cdef enum Spam:
a
b, c,
d, e, f
g = 42
cdef void eggs():
cdef Spam s1, s2
cdef int i
s1 = s2
s1 = c
i = s1
\ No newline at end of file
cdef int i, j, k
cdef object a, b, x
for i from 0 <= i < 10:
pass
for i from 0 < i <= 10:
pass
for i from 10 >= i > 0:
pass
for i from 10 > i >= 0:
pass
for x from 0 <= x <= 10:
pass
for i from a <= i <= b:
pass
for i from k <= i <= j:
pass
for i from k * 42 <= i <= j / 18:
pass
while j:
for i from 0 <= i <= 10:
continue
break
else:
continue
break
class Swallow:
def spam(w, int x = 42, y = "grail", z = swallow):
pass
cdef extern void spam(char *s)
cdef struct Grail:
char silly[42]
cdef void eggs():
cdef char silly[42]
cdef Grail grail
spam(silly)
spam(grail.silly)
cdef void f():
cdef void *p
cdef char *q
p = q
cdef extern (int *[42]) spam, grail, swallow
cdef (int (*)()) brian():
pass
cdef enum Grail:
k = 42
cdef enum Spam:
a = -1
b = 2 + 3
c = 42 > 17
d = k
cdef class Tst:
cdef foo,
ctypedef struct Foo:
int blarg
cdef Foo f():
blarg = 1 + 2
DEF CHAR = c'x'
DEF INT = 42
DEF LONG = 666L
DEF FLOAT = 17.88
DEF STR = "spam"
DEF TUPLE = (1, 2, "buckle my shoe")
DEF TWO = TUPLE[1]
DEF FIVE = TWO + 3
cdef void f():
cdef char c
cdef int i
cdef long l
cdef float f
cdef char *s
cdef int two
cdef int five
c = CHAR
i = INT
l = LONG
f = FLOAT
s = STR
two = TWO
five = FIVE
\ No newline at end of file
ctypedef int *IntPtr
ctypedef unsigned long ULong
cdef extern IntPtr spam
cdef extern ULong grail
ctypedef class spam:
pass
cdef spam s
s = None
ctypedef enum parrot_state:
alive = 1
dead = 2
cdef parrot_state polly
polly = dead
ctypedef struct order:
int spam
int eggs
cdef order order1
order1.spam = 7
order1.eggs = 2
ctypedef union pet:
int cat
float dog
cdef pet sam
sam.cat = 1
sam.dog = 2.7
cdef extern short int s
cdef extern long int l
cdef extern long long ll
cdef extern long double ld
cdef struct Sandwich:
int i
char *s
cdef class Tomato:
cdef float danger
cdef class Tomato:
def eject(self):
pass
cdef extern Sandwich butty
cdef Tomato supertom
supertom = None
cdef extern char *cp
cdef extern char *cpa[5]
cdef extern int (*ifnpa[5])()
cdef extern char *(*cpfnpa[5])()
cdef extern int (*ifnp)()
cdef extern int (*iap)[5]
cdef extern int ifn()
cdef extern char *cpfn()
cdef extern int (*iapfn())[5]
cdef extern char *(*cpapfn())[5]
cdef extern int fnargfn(int ())
cdef void f():
cdef void *p
global ifnp, cpa
ifnp = <int (*)()>p
cdef char *g():
pass
cdef class Spam:
pass
cdef Spam foo():
return blarg()
#cdef Spam grail
#grail = blarg()
#return grail
cdef object blarg():
pass
cdef void f():
try:
pass
finally:
pass
cdef enum E:
a
cdef enum G:
b
cdef void f():
cdef E e
cdef G g
cdef int i, j
cdef float f, h
i = j | e
i = e | j
i = j ^ e
i = j & e
i = j << e
i = j >> e
i = j + e
i = j - e
i = j * e
i = j / e
i = j % e
# f = j ** e # Cython prohibits this
i = e + g
f = h
cdef class C:
cdef f(self):
pass
cdef void f():
"This is a pseudo doc string."
# Spurious gcc3.3 warnings about incompatible pointer
# types passed to C method
# Ordering of declarations in C code is important
cdef class C
cdef class D(C)
cdef class E
cdef class C:
cdef void a(self):
pass
cdef class D(C):
cdef void m(self, E e):
pass
cdef class E:
pass
cdef void f(D d, E e):
d.m(e)
cdef class A:
cdef void f(self, x):
pass
cdef class B(A):
cdef void f(self, object x):
pass
cdef extern void g(A a, b)
cdef extern void g(A a, b)
cdef struct Foo
cdef class Blarg
ctypedef Foo FooType
ctypedef Blarg BlargType
cdef struct Foo:
FooType *f
cdef class Blarg:
cdef FooType *f
cdef BlargType b
cdef class Blarg:
pass
cdef struct xmlDoc
cdef struct xmlDoc:
int i
cdef int spam() except 42:
pass
cdef float eggs() except 3.14:
pass
cdef char *grail() except NULL:
pass
cdef int tomato() except *:
pass
cdef int brian() except? 0:
pass
cdef int silly() except -1:
pass
cdef extern class somewhere.Swallow:
pass
cdef Swallow swallow
def spam(x = swallow, Swallow y = swallow):
pass
cdef class Spam:
cdef int tons
cdef void add_tons(self, int x):
pass
cdef class SuperSpam(Spam):
pass
cdef void tomato():
cdef Spam spam
cdef SuperSpam superspam
spam = superspam
spam.add_tons(42)
superspam.add_tons(1764)
cdef class Spam:
def __delattr__(self, n):
pass
cdef class Spam:
def __delitem__(self, i):
pass
cdef class Spam:
def __delslice__(self, Py_ssize_t i, Py_ssize_t j):
pass
cdef extern int i
cdef extern char *s[]
cdef extern void spam(char c)
cdef extern int eggs():
pass
cdef int grail():
pass
cdef class Spam
cdef class Grail:
cdef Spam spam
cdef class Spam:
pass
cdef class Spam:
def __getattr__(self, x):
pass
cdef class Spam:
def __hash__(self):
pass
cdef extern class Spam.Eggs.Ham:
pass
cdef Ham ham
ham = None
\ No newline at end of file
cdef class Spam:
def __index__(self):
return 42
cdef class Parrot:
pass
cdef class Norwegian(Parrot):
def __delitem__(self, i):
pass
def __delslice__(self, i, j):
pass
def __delattr__(self, n):
pass
def __delete__(self, i):
pass
cdef class Parrot:
pass
cdef class Norwegian(Parrot):
def __setitem__(self, i, x):
pass
def __setslice__(self, i, j, x):
pass
def __setattr__(self, n, x):
pass
def __set__(self, i, v):
pass
cdef class Spam:
property eggs:
def __del__(self):
pass
cdef class Spam:
property eggs:
"Ova"
cdef class Spam:
property eggs:
def __get__(self):
pass
cdef class Spam:
property eggs:
def __set__(self, x):
pass
cdef class Spam:
def __setattr__(self, n, x):
pass
cdef class Spam:
def __setitem__(self, i, x):
pass
cdef class Spam:
def __setslice__(self, Py_ssize_t i, Py_ssize_t j, x):
pass
def f(a, b, c):
cdef int i
for a in b:
i = 1
continue
i = 2
break
i = 3
for i in b:
i = 1
for a in "spam":
i = 1
for a[b] in c:
i = 1
for a,b in c:
i = 1
for a in b,c:
i = 1
\ No newline at end of file
cdef int x
x = 42
y = 88
def f():
from spam import eggs
from spam.morespam import bacon, eggs, ham
from spam import eggs as ova
\ No newline at end of file
cdef int grail():
cdef int (*spam)()
spam = &grail
spam = grail
spam()
cdef int f() except -1:
g = getattr3
global __name__
print __name__
cdef int a_global_int
cdef a_global_pyobject
a_global_int = 0
a_global_pyobject = None
\ No newline at end of file
typedef struct {
PyObject_HEAD
} PySpamObject;
cdef extern from "hinsen1.h":
ctypedef class spam.Spam [object PySpamObject]:
pass
cdef class SpamAndEggs(Spam):
cdef cook(self):
pass
cdef class vector:
def __div__(vector self, double factor):
result = vector()
return result
cdef enum Color:
red
white
blue
cdef void f():
cdef Color e
cdef int i
i = red
i = red + 1
i = red | 1
e = white
i = e
i = e + 1
cdef:
struct PrivFoo:
int i
int priv_i
void priv_f():
global priv_i
priv_i = 42
cdef public:
struct PubFoo:
int i
int pub_v
void pub_f():
pass
class PubBlarg [object PubBlargObj, type PubBlargType]:
pass
cdef api:
void api_f():
pass
cdef public api:
void pub_api_f():
pass
def f():
import spam
import spam.eggs
import spam, eggs, ham
import spam as tasty
\ No newline at end of file
cdef class A:
def __getitem__(self, x):
pass
cdef void __stdcall f():
pass
cdef class Position
cdef class Point(Position)
cdef class Vector(Point)
cdef class CoordSyst
cdef void test(float* f):
pass
cdef class Position:
cdef readonly CoordSyst parent
cdef class Point(Position):
cdef void bug(self):
test(self.parent._matrix)
cdef class Vector(Point):
cdef void bug(self):
test(self.parent._matrix)
cdef class CoordSyst:
cdef float* _matrix
cdef class A:
cdef object x
cdef class C:
cdef object foo
cdef object __weakref__
cdef class T:
cdef int a[1]
cdef object b
cdef void f(void *obj):
(<T> obj).a[0] = 1
b = None
def f(x,):
pass
cdef void g(int x,):
pass
ctypedef struct BB:
void (*f) (void* state)
cdef extern unsigned long x
cdef extern long unsigned y
cdef extern object g(object x) nogil
cdef void f(int x) nogil:
cdef int y
y = 42
cdef class spam:
pass
cdef spam s
s = None
cdef char *p1
cdef int *p2
cdef int x
p1 = NULL
p2 = NULL
x = p1 == NULL
x = NULL == p2
cdef extern void spam(int, char *)
class Spam:
def eggs(self):
pass
cdef struct S:
char c
unsigned char uc
signed char sc
short s
unsigned short us
signed short ss
int i
unsigned int ui
signed int si
long l
unsigned long ul
signed long sl
long long ll
unsigned long long ull
signed long long sll
cdef class Grail:
def __cinit__(self, spam = None):
pass
def __init__(self, parrot = 42):
pass
cdef class C:
def __init__(self):
"This is an unusable docstring."
property foo:
def __get__(self):
"So is this."
def __set__(self, x):
"And here is another one."
cdef class Spam:
cdef int eggs
def __iadd__(self, Spam other):
self.eggs = self.eggs + other.eggs
def f(a, b, c, x):
cdef int i
a = b + c
try:
i = 1
raise x
i = 2
except a:
i = 3
try:
i = 1
except a:
i = 2
except b:
i = 3
try:
i = 1
except a, b:
i = 2
try:
i = 1
except a:
i = 2
except:
i = 3
try:
i = 1
except (a, b), c[42]:
i = 2
for a in b:
try:
c = x * 42
except:
i = 17
try:
i = 1
except:
raise
def f(a, b, c, x):
cdef int i
a = b + c
try:
return
raise a
finally:
c = a - b
for a in b:
try:
continue
break
c = a * b
finally:
i = 42
\ No newline at end of file
cdef void f(obj):
cdef int i
cdef char *p
p = <char *>i
obj = <object>p
p = <char *>obj
\ No newline at end of file
cdef grail(char *blarg, ...):
pass
def f(a, b):
cdef int i
while a:
x = 1
while a+b:
x = 1
while i:
x = 1
else:
x = 2
while i:
x = 1
break
x = 2
else:
x = 3
while i:
x = 1
continue
x = 2
\ No newline at end of file
cdef void f() with gil:
x = 42
cdef object g(object x) with gil:
pass
cdef object f(object x):
cdef int y
#z = 42
with nogil:
pass#y = 17
#z = 88
cdef object g():
with nogil:
h()
cdef int h() except -1:
pass
def f():
cdef int int1, int2, int3
cdef char *ptr1, *ptr2, *ptr3
obj1 = 1
obj2 = 2
obj3 = 3
int1 = int2 + int3
ptr1 = ptr2 + int3
ptr1 = int2 + ptr3
obj1 = obj2 + int3
\ No newline at end of file
def f():
cdef int i
cdef int *p
p = &i
__doc__ = """
>>> iter(C())
Traceback (most recent call last):
TypeError: iter() returned non-iterator of type 'NoneType'
"""
cdef class C:
def __iter__(self):
"This is a doc string."
def f(a):
global f
f = a
f = 42
def f(a, b):
cdef int i
assert a
assert a+b
assert i
def g(a, b):
assert a, b
def f(a, b):
a = b.spam
a.spam = b
a = b.spam.eggs
a.spam.eggs = b
\ No newline at end of file
cdef class MyClass:
pass
def foo(MyClass c):
cdef MyClass res
res = c
return res
def f(obj1, obj2):
obj1 = `obj2`
obj1 = `42`
\ No newline at end of file
cdef class Spam:
cdef eggs(self):
pass
cdef Spam spam():
pass
def viking():
return spam().eggs()
__doc__ = """
>>> y
1
>>> y and {}
{}
>>> x
{}
"""
y = 1
x = y and {}
__doc__ = """
>>> y
>>> y or {}
{}
>>> x
{}
"""
y = None
x = y or {}
cdef class fmatrix:
cdef int foo
def __setitem__(self, int key, int value):
if key:
self.foo = value
return
self.foo = not value
cdef class foo:
def __contains__(self, key):
return 1
cdef void foo(obj1, obj2, obj3, obj4, obj5):
cdef int bool1, bool2, bool3, bool4
cdef char *ptr
cdef float f
bool3 = bool1 and bool2
bool3 = bool1 or bool2
bool3 = obj1 and obj2
bool3 = bool1 and ptr
bool3 = bool1 and f
bool4 = bool1 and bool2 and bool3
bool4 = bool1 or bool2 and bool3
obj4 = obj1 and obj2 and obj3
obj5 = (obj1 + obj2 + obj3) and obj4
cdef void ftang():
cdef int x
x = 0
cdef int foo(int i, char c):
cdef float f, g
f = 0
g = 0
cdef spam(int i, obj, object object):
cdef char c
c = 0
def f():
cdef int int1, int2, int3
cdef char char1
cdef long long1, long2
int1 = int2 | int3
int1 = int2 ^ int3
int1 = int2 & int3
int1 = int2 << int3
int1 = int2 >> int3
int1 = int2 << int3 | int2 >> int3
long1 = char1 | long2
\ No newline at end of file
spam = "C string 1" + "C string 2"
spam = "eggs" * 42
grail = 17 * "tomato"
cdef struct Grail
cdef struct Spam:
int i
char c
float *p[42]
Grail *g
cdef struct Grail:
Spam *s
cdef Spam spam, ham
cdef void eggs(Spam s):
cdef int j
j = s.i
s.i = j
spam = ham
cdef union Spam:
int i
char c
float *p[42]
cdef Spam spam, ham
cdef void eggs(Spam s):
cdef int j
j = s.i
s.i = j
spam = ham
def f():
cdef char a_char
cdef short a_short
cdef int i1, i2
cdef long a_long
cdef float a_float
cdef double a_double
cdef unsigned char an_unsigned_char
cdef unsigned short an_unsigned_short
cdef unsigned int an_unsigned_int
cdef unsigned long an_unsigned_long
cdef char *a_char_ptr, *another_char_ptr
cdef char **a_char_ptr_ptr
cdef char ***a_char_ptr_ptr_ptr
cdef char a_sized_char_array[10]
cdef char a_2d_char_array[10][20]
cdef char *a_2d_char_ptr_array[10][20]
cdef char **a_2d_char_ptr_ptr_array[10][20]
cdef int (*a_0arg_function)()
cdef int (*a_1arg_function)(int i)
cdef int (*a_2arg_function)(int i, int j)
cdef void (*a_void_function)()
a_char = 0
a_short = 0
i1 = 0
i2 = 0
a_long = 0
a_float = 0
a_double = 0
an_unsigned_char = 0
an_unsigned_short = 0
an_unsigned_int = 0
an_unsigned_long = 0
a_char_ptr = NULL
another_char_ptr = NULL
a_char_ptr_ptr = NULL
a_char_ptr_ptr_ptr = NULL
a_sized_char_array[0] = 0
a_2d_char_array[0][0] = 0
a_2d_char_ptr_array[0][0] = NULL
a_2d_char_ptr_ptr_array[0][0] = NULL
a_0arg_function = NULL
a_1arg_function = NULL
a_2arg_function = NULL
a_void_function = NULL
def f(adict, key1, value1, key2, value2):
adict = {}
adict = {key1:value1}
adict = {key1:value1, key2:value2}
adict = {key1:value1, key2:value2,}
adict = {"parrot":"resting", "answer":42}
\ No newline at end of file
def test():
cdef float v[10][10]
v[1][2] = 1.0
print v[1][2]
"Welcome to the parrot module. It is currently resting."
def zap(polly, volts):
"Wake up polly."
class Parrot:
"Standard Norwegian Blue."
def admire_plumage(self):
"Lovely, ain't it?"
cdef class SuperParrot:
"Special high-performance model."
cdef class Point:
cdef double x, y, z
def __init__(self, double x, double y, double z):
self.x = x
self.y = y
self.z = z
# XXX
def __add__(self, other):
return Point(self.x + other.x, self.y + other.y, self.z + other.z)
cdef class Eggs: pass
cdef class Parrot:
cdef object name
cdef int alive
cdef class Norwegian(Parrot):
cdef object plumage_colour
cdef void rest(Norwegian polly):
cdef Parrot fred
cdef object spam
fred = polly
polly = fred
polly = spam
spam = polly
polly.alive = 0
cdef class Spam:
pass
def f():
s = Spam()
cdef class Spam:
def __len__(self):
return 0
cdef class Silly:
def __init__(self, *a):
pass
def spam(self, x, y, z):
pass
def grail(self, x, y, z, *a):
pass
def swallow(self, x, y, z, **k):
pass
def creosote(self, x, y, z, *a, **k):
pass
__doc__ = """
>>> s = Spam(12)
>>> s.eat()
12 42
>>> f(s)
Traceback (most recent call last):
AttributeError: 'exttype.Spam' object has no attribute 'foo'
>>> s.eat()
12 42
>>> class Spam2(Spam):
... foo = 1
>>> s = Spam2(12)
>>> s.eat()
12 42
>>> f(s)
>>> s.eat()
12 42
"""
cdef gobble(a, b):
print a, b
cdef class Spam:
cdef eggs
cdef int ham
def __cinit__(self, eggs):
self.eggs = eggs
self.ham = 42
def __dealloc__(self):
self.ham = 0
def eat(self):
gobble(self.eggs, self.ham)
def f(Spam spam):
x = spam.eggs
y = spam.ham
z = spam.foo
spam.eggs = x
spam.ham = y
spam.foo = z
include "filenames.pxi"
foo = 42
def f(a, b):
if a:
x = 1
if a+b:
x = 1
if a:
x = 1
elif b:
x = 2
if a:
x = 1
elif b:
x = 2
else:
x = 3
\ No newline at end of file
class C:
def xxx(self, p="a b"):
pass
cdef class C1:
pass
cdef class C2:
cdef C1 c1
def __init__(self, arg):
self.c1 = arg
__doc__ = """
>>> py_x = r'\\\\'
>>> assert x == py_x
"""
x = r'\\'
cdef class TEST:
def __contains__(self, x):
return 42
class X:
slots = ["", ]
def c(a, b, c):
z = 33
def d(a, b, *, c = 88):
z = 44
def e(a, b, c = 88, **kwds):
z = 55
def f(a, b, *, c, d = 42):
z = 66
def g(a, b, *, c, d = 42, e = 17, f, **kwds):
z = 77
def h(a, b, *args, c, d = 42, e = 17, f, **kwds):
z = 88
cdef class A:
cdef double x[3]
def __getitem__(self,i):
return self.x[i]
def f(obj1, obj2, obj3, obj4, obj5):
obj1 = []
obj1 = [obj2]
obj1 = [obj2, obj3]
obj1 = [obj2, obj3, obj4]
obj1 = [17, 42, 88]
\ No newline at end of file
def foo():
a = 42
a1 = 0123
a2 = 0xabc
a3 = 0xDEF
a4 = 1234567890L
b = 42.88e17
b0a = 1.
b0b = .1
b0c = 1.1
b0d = 1.e1
b0e = .1e1
b0f = 1.1e1
b0g = 1.1e-1
b0h = 1e1
b1 = 3j
b2 = 3.1415J
b3 = c'X'
c = "spanish inquisition"
d = "this" "parrot" "is" "resting"
e = 'single quoted string'
f = '"this is quoted"'
g = '''Triple single quoted string.'''
h = """Triple double quoted string."""
g1 = '''Two line triple
single quoted string.'''
h1 = """Two line triple
double quoted string."""
i = 'This string\
has an ignored newline.'
j = 'One-char escapes: \'\"\\\a\b\f\n\r\t\v'
k = 'Oct and hex escapes: \1 \12 \123 \x45 \xaf \xAF'
l = r'''This is\
a \three \line
raw string with some backslashes.'''
m = 'Three backslashed ordinaries: \c\g\+'
n = '''Triple single quoted string
with ' and " quotes'''
o = """Triple double quoted string
with ' and " quotes"""
p = "name_like_string"
q = "NameLikeString2"
r = "99_percent_un_namelike"
s = "Not an \escape"
def f():
pass
g = 42
x = "spam"
y = "eggs"
if g:
z = x + y
def f():
cdef int int1, int2, int3
cdef char *str2, *str3
obj1 = 1
obj2 = 2
obj3 = 3
int1 = int2 % int3
obj1 = str2 % str3
obj1 = obj2 % obj3
\ No newline at end of file
cdef void f():
cdef object obj1a, obj2a, obj3a, obj1b, obj2b, obj3b
cdef int int1, int2
cdef char *ptr1, *ptr2
obj1a, obj2a = obj1b, obj2b
obj1a, [obj2a, obj3a] = [obj1b, (obj2b, obj3b)]
int1, ptr1, obj1a = int2, ptr2, obj1b
obj1a, obj2a, obj3a = obj1b + 1, obj2b + 2, obj3b + 3
def f(a, *p, **n):
pass
import sys
def test(obj):
print "Raising:", repr(obj)
try:
raise obj
except:
info = sys.exc_info()
print "Caught: %r %r" % (info[0], info[1])
cdef class Tri:
pass
cdef class Curseur:
cdef Tri tri
def detail(self):
produire_fiches(self.tri)
cdef produire_fiches(Tri tri):
pass
x = 1,
x = 1, 2,
cdef enum Mode:
a = 1
b = 2
cdef class Curseur:
cdef Mode mode
def method(self):
assert False, self.mode
cdef class Fiche:
def __setitem__(self, element, valeur):
if valeur is None:
return
def f(a, b):
print
print a
print a, b
print a, b,
print 42, "spam"
\ No newline at end of file
__doc__ = """
>>> f()
>>> g()
"""
def f():
cdef int bool, int1, int2
obj1 = 1
obj2 = 2
bool = obj1 == obj2
assert not bool
bool = obj1 <> int2
assert bool
bool = int1 == obj2
assert not bool
bool = obj1 is obj2
assert not bool
bool = obj1 is not obj2
assert bool
def g():
cdef int bool
obj1 = 1
obj2 = []
bool = obj1 in obj2
assert not bool
bool = obj1 not in obj2
assert bool
cdef class Eggs:
cdef object ham
cdef class Spam:
cdef Eggs eggs
cdef void tomato(Spam s):
food = s.eggs.ham
def f():
obj1 = 1
obj2 = 2
obj3 = 3
obj1 = obj2 | obj3
obj1 = obj2 ^ obj3
obj1 = obj2 & obj3
obj1 = obj2 << obj3
obj1 = obj2 >> obj3
obj1 = obj2 << obj3 | obj2 >> obj3
\ No newline at end of file
__doc__ = """
>>> f()
6
>>> g()
0
"""
def f():
obj1 = 1
obj2 = 2
obj3 = 3
obj1 = obj2 * obj3
return obj1
def g():
obj1 = 1
obj2 = 2
obj3 = 3
obj1 = obj2 / obj3
return obj1
__doc__ = """
>>> def test(a, b):
... print a, b, add(a, b)
>>> test(1, 2)
1 2 3
>>> test(17.3, 88.6)
17.3 88.6 105.9
>>> test("eggs", "spam")
eggs spam eggsspam
"""
def add(x, y):
return x + y
__doc__ = """
>>> swallow(name = "Brian")
This swallow is called Brian
>>> swallow(airspeed = 42)
This swallow is flying at 42 furlongs per fortnight
>>> swallow(coconuts = 3)
This swallow is carrying 3 coconuts
"""
def swallow(name = None, airspeed = None, coconuts = None):
if name is not None:
print "This swallow is called", name
if airspeed is not None:
print "This swallow is flying at", airspeed, "furlongs per fortnight"
if coconuts is not None:
print "This swallow is carrying", coconuts, "coconuts"
__doc__ = """
>>> try:
... B()
... except Exception, e:
... print "%s: %s" % (e.__class__.__name__, e)
Exception: crash-me
"""
cdef class A:
def __cinit__(self):
raise Exception("crash-me")
cdef class B(A):
def __cinit__(self):
print "hello world"
__doc__ = """
foo = Foo()
fee = Fee()
faa = Faa()
fee.bof()
faa.bof()
"""
cdef class Foo:
cdef int val
def __init__(self):
self.val = 0
cdef class Fee(Foo):
def bof(self):
print 'Fee bof', self.val
cdef class Faa(Fee):
def bof(self):
print 'Foo bof', self.val
__doc__ = """
print f(100)
print g(3000000000)
"""
def f(x):
cdef unsigned long long ull
ull = x
return ull + 1
def g(unsigned long x):
return x + 1
__doc__ = """
try:
eggs().eat()
except RuntimeError, e:
print "%s: %s" % (e.__class__.__name__, e)
"""
cdef class eggs:
def __dealloc__(self):
pass
def eat(self):
raise RuntimeError("I don't like that")
__doc__ = """
>>> print f.__doc__
This is a function docstring.
>>> print C.__doc__
This is a class docstring.
>>> print T.__doc__
This is an extension type docstring.
"""
def f():
"This is a function docstring."
class C:
"This is a class docstring."
cdef class T:
"This is an extension type docstring."
__doc__ = """
>>> c = eggs()
>>> print "eggs returned:", c
eggs returned: (17+42j)
>>> spam(c)
Real: 17.0
Imag: 42.0
"""
cdef extern from "complexobject.h":
struct Py_complex:
double real
double imag
ctypedef class __builtin__.complex [object PyComplexObject]:
cdef Py_complex cval
def spam(complex c):
print "Real:", c.cval.real
print "Imag:", c.cval.imag
def eggs():
return complex(17, 42)
__doc__ = """
>>> s = Swallow("Brian", 42)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {}
>>> s = Swallow("Brian", 42, "African")
Name: Brian
Airspeed: 42
Extra args: ('African',)
Extra keywords: {}
>>> s = Swallow("Brian", airspeed = 42)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {}
>>> s = Swallow("Brian", airspeed = 42, species = "African", coconuts = 3)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {'coconuts': 3, 'species': 'African'}
>>> s = Swallow("Brian", 42, "African", coconuts = 3)
Name: Brian
Airspeed: 42
Extra args: ('African',)
Extra keywords: {'coconuts': 3}
"""
cdef class Swallow:
def __init__(self, name, airspeed, *args, **kwds):
print "Name:", name
print "Airspeed:", airspeed
print "Extra args:", args
print "Extra keywords:", kwds
__doc__ = """
>>> go()
Spam!
Spam!
Spam!
Spam!
Spam!
"""
def go():
for i in range(5):
print "Spam!"
__doc__ = """
>>> try:
... s = Spam()
... except StandardError, e:
... print "Exception:", e
... else:
... print "Did not raise the expected exception"
Exception: This is not a spanish inquisition
"""
cdef extern from "Python.h":
ctypedef class types.ListType [object PyListObject]:
pass
cdef class Spam(ListType):
def __init__(self):
raise StandardError("This is not a spanish inquisition")
__doc__ = """
try:
foo()
except Exception, e:
print "%s: %s" % (e.__class__.__name__, e)
"""
def bar():
try:
raise TypeError
except TypeError:
pass
def foo():
try:
raise ValueError
except ValueError, e:
bar()
raise
__doc__ = """
print r_jeff_epler_1.blowup([2, 3, 5])
"""
def blowup(p):
cdef int n, i
n = 10
i = 1
return n % p[i]
cdef class Parrot:
cdef void describe(self)
cdef class Norwegian(Parrot):
pass
cdef class Parrot:
cdef void describe(self):
print "This parrot is resting."
def describe_python(self):
self.describe()
cdef class Norwegian(Parrot):
cdef void describe(self):
print "Lovely plumage!"
cdef Parrot p1, p2
p1 = Parrot()
p2 = Norwegian()
p1.describe()
p2.describe()
__doc__ = """
g = r_lepage_3.Grail()
g("spam", 42, ["tomato", "sandwich"])
"""
cdef class Grail:
def __call__(self, x, y, z):
print "Grail called with:", x, y, z
import re
t = re.search('(\d+)', '-2.80 98\n').groups()
class Bicycle:
def fall_off(self, how_hard = "extremely"):
print "Falling off", how_hard, "hard"
def boolExpressionsFail():
dict = {1: 1}
if not dict.has_key("2b"):
return "Not 2b"
else:
return "2b?"
__doc__ = """
>>> print primes(20)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71]
"""
def primes(int kmax):
cdef int n, k, i
cdef int p[1000]
result = []
if kmax > 1000:
kmax = 1000
k = 0
n = 2
while k < kmax:
i = 0
while i < k and n % p[i] <> 0:
i = i + 1
if i == k:
p[k] = n
k = k + 1
result.append(n)
n = n + 1
return result
__doc__ = """
>>> frighten()
NOBODY expects the Spanish Inquisition!
"""
def frighten():
print "NOBODY", "expects", "the Spanish Inquisition!"
__doc__ = """
>>> order()
42 tons of spam!
"""
class Spam:
def __init__(self, w):
self.weight = w
def serve(self):
print self.weight, "tons of spam!"
def order():
s = Spam(42)
s.serve()
__doc__ = """
>>> c = CoconutCarrier()
>>> c.swallow(name = "Brian")
This swallow is called Brian
>>> c.swallow(airspeed = 42)
This swallow is flying at 42 furlongs per fortnight
>>> c.swallow(coconuts = 3)
This swallow is carrying 3 coconuts
"""
class CoconutCarrier:
def swallow(self, name = None, airspeed = None, coconuts = None):
if name is not None:
print "This swallow is called", name
if airspeed is not None:
print "This swallow is flying at", airspeed, "furlongs per fortnight"
if coconuts is not None:
print "This swallow is carrying", coconuts, "coconuts"
__doc__ = """
>>> x = spam()
>>> print repr(x)
'Ftang\\x00Ftang!'
"""
cdef extern from "string.h":
void memcpy(char *d, char *s, int n)
cdef extern from "Python.h":
object PyString_FromStringAndSize(char *s, int len)
def spam():
cdef char buf[12]
memcpy(buf, "Ftang\0Ftang!", sizeof(buf))
return PyString_FromStringAndSize(buf, sizeof(buf))
__doc__ = """
>>> s = Spam()
>>> print s.get_tons()
17
>>> s.set_tons(42)
>>> print s.get_tons()
42
>>> s = None
42 tons of spam is history.
"""
cdef class Spam:
cdef int tons
def __cinit__(self):
self.tons = 17
def __dealloc__(self):
print self.tons, "tons of spam is history."
def get_tons(self):
return self.tons
def set_tons(self, x):
self.tons = x
__doc__ = """
>>> eggs()
Args: 1 2 3
Args: buckle my shoe
"""
def spam(a, b, c):
print "Args:", a, b, c
def eggs():
spam(*(1,2,3))
spam(*["buckle","my","shoe"])
__doc__ = """
>>> swallow("Brian", 42)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {}
>>> swallow("Brian", 42, "African")
Name: Brian
Airspeed: 42
Extra args: ('African',)
Extra keywords: {}
>>> swallow("Brian", airspeed = 42)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {}
>>> swallow("Brian", airspeed = 42, species = "African", coconuts = 3)
Name: Brian
Airspeed: 42
Extra args: ()
Extra keywords: {'coconuts': 3, 'species': 'African'}
>>> swallow("Brian", 42, "African", coconuts = 3)
Name: Brian
Airspeed: 42
Extra args: ('African',)
Extra keywords: {'coconuts': 3}
"""
def swallow(name, airspeed, *args, **kwds):
print "Name:", name
print "Airspeed:", airspeed
print "Extra args:", args
print "Extra keywords:", kwds
__doc__ = """
>>> spam()
Args: ()
>>> spam(42)
Args: (42,)
>>> spam("one", 2, "buckle my shoe")
Args: ('one', 2, 'buckle my shoe')
"""
def spam(*args):
print "Args:", args
__doc__ = """
>>> s = Spam()
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (0 given)
"""
cdef class Spam:
def __init__(self, a, b, int c):
pass
def test(k):
cdef unsigned long m
m = k
return m
def f():
a = 42
b = a
def f(a):
return
return a
return 42
cdef void g():
return
cdef int h(a):
cdef int i
return i
\ No newline at end of file
class B:
def __init__(self):
self.t = {
1 : (
(1, 2, 3)
,
)
, 2 : ( 1, 2, 3)
}
def f(x, y):
x = y
cdef void g(int i, float f, char *p):
f = i
cdef h(int i, obj):
i = obj
def z(a, b, c):
f()
f(a)
f(a, b)
f(a, b,)
g(1, 2.0, "spam")
g(a, b, c)
h(42, "eggs")
\ No newline at end of file
cdef struct Spam:
char *grail
cdef void f():
cdef int i, j, k
cdef char *p
i = sizeof(p)
i = sizeof(j + k)
i = sizeof(int)
i = sizeof(Spam)
def f(obj1, obj2, obj3, obj4):
obj1 = obj2[:]
obj1 = obj2[obj3:]
obj1 = obj2[:obj4]
obj1 = obj2[obj3:obj4]
def f(obj1, obj2, obj3, obj4, obj5):
cdef int int3, int4, int5
obj1 = obj2[...]
obj1 = obj2[::]
obj1 = obj2[obj3::]
obj1 = obj2[:obj4:]
obj1 = obj2[::obj5]
obj1 = obj2[obj3:obj4:]
obj1 = obj2[obj3::obj5]
obj1 = obj2[:obj4:obj5]
obj1 = obj2[obj3:obj4:obj5]
obj1 = obj2[int3:int4:int5]
obj1[int3:int4:int5] = obj2
\ No newline at end of file
def spam(x, y, z):
pass
def grail(x, y, z, *a):
pass
def swallow(x, y, z, **k):
pass
def creosote(x, y, z, *a, **k):
pass
def f():
cdef int int1, int2, int3
cdef char *ptr1, *ptr2, *ptr3
obj1 = 1
obj2 = 2
obj3 = 3
int1 = int2 - int3
ptr1 = ptr2 - int3
int1 = ptr2 - ptr3
obj1 = obj2 - int3
\ No newline at end of file
def f(obj1, obj2, obj3, obj4, obj5):
obj1 = ()
obj1 = (obj2,)
obj1 = obj2, obj3
obj1 = (obj2, obj3, obj4)
obj1 = (obj2, obj3, obj4,)
obj1 = 17, 42, 88
def f(obj1, obj2, obj3):
cdef int bool1, bool2
cdef int int1, int2
cdef char *str1
bool1 = not bool2
obj1 = not obj2
bool1 = not str1
int1 = +int2
obj1 = +obj2
int1 = -int2
obj1 = -obj2
int1 = ~int2
obj1 = ~obj2
\ No newline at end of file
def f(obj1, obj2, obj3, obj4, obj5):
obj1, = obj2
obj1, = obj2 + obj3
obj1, obj2, obj3 = obj3
obj1, (obj2, obj3) = obj4
[obj1, obj2] = obj3
\ No newline at end of file
cdef grail(char *blarg, ...):
pass
cdef swallow():
grail("spam")
grail("spam", 42)
cdef unsigned int ui
x = ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment