def f(Grail g):
cdef int i = 0
cdef Swallow s
+ cdef object x
g = x
x = g
g = i
cdef class vector:
def __div__(vector self, double factor):
- result = vector()
+ cdef object result = vector()
return result
neg
pos
"""
+ cdef object D
cdef long neg = -1
cdef unsigned long pos = -2 # will be a large positive number
...
ValueError: Buffer dtype mismatch, expected 'int' but got end in 'Char3Int.d'
"""
- obj = MockBuffer(fmt, sizeof(Char3Int))
+ cdef object obj = MockBuffer(fmt, sizeof(Char3Int))
cdef object[Char3Int, ndim=1] buf = obj
@testcase
assert (sizeof(UnpackedStruct1) == sizeof(UnpackedStruct2)
== sizeof(UnpackedStruct3) == sizeof(UnpackedStruct4))
- obj = MockBuffer(fmt, sizeof(UnpackedStruct1))
+ cdef object obj = MockBuffer(fmt, sizeof(UnpackedStruct1))
cdef object[UnpackedStruct1, ndim=1] buf1 = obj
cdef object[UnpackedStruct2, ndim=1] buf2 = obj
cdef object[UnpackedStruct3, ndim=1] buf3 = obj
ValueError: Buffer dtype mismatch, expected 'float' but got 'complex float' in 'ComplexFloat.imag'
"""
- obj = MockBuffer(fmt, sizeof(ComplexTest))
+ cdef object obj = MockBuffer(fmt, sizeof(ComplexTest))
cdef object[ComplexTest] buf1 = obj
print test_file_c(arg)
print len(arg)
print type(arg)
+
+def test_for_in_range(arg):
+ """
+ >>> print(str(test_for_in_range('abc')).replace("u'", "'"))
+ ['r', 'a', 'n', 'g', 'e', 'a', 'b', 'c']
+ """
+ l = []
+ for c in range(arg):
+ l.append(c)
+ return l
>>> call0()
(True, u'yo')
"""
- a = A()
+ cdef A a = A()
return a.foo()
def call1():
>>> call1()
(False, u'yo')
"""
- a = A()
+ cdef A a = A()
return a.foo(False)
def call2():
>>> call2()
(False, u'go')
"""
- a = A()
+ cdef A a = A()
return a.foo(False, u"go")
"""
>>> no_cdef()
"""
- lst = list(range(11))
+ cdef object lst = list(range(11))
ob = 10L
lst[ob] = -10
- dd = {}
+ cdef object dd = {}
dd[ob] = -10
def with_cdef():
>>> f(2,(1,2,3))
True
"""
- result = a in b
+ cdef object result = a in b
return result
def g(a,b):
>>> g(2,(1,2,3))
1
"""
- cdef int result
- result = a in b
+ cdef int result = a in b
return result
def h(b):
>>> h([1,3,4])
False
"""
- result = 2 in b
+ cdef object result = 2 in b
return result
def j(b):
>>> j([1,3,4])
0
"""
- cdef int result
- result = 2 in b
+ cdef int result = 2 in b
return result
def k(a):
>>> r(2)
1
"""
- l = [1,2,3,4]
- l2 = [l[1:],l[:-1],l]
+ cdef object l = [1,2,3,4]
+ cdef object l2 = [l[1:],l[:-1],l]
cdef int result = a in l in l2
return result
c side effect 4
([0, 11, 102, 3, 4], [0, 1, 2, 13, 104])
"""
- a = list(range(5))
+ cdef object a = list(range(5))
a[side_effect(1)] += 10
a[c_side_effect(2)] += 100
cdef int i
cdef class A:
pass
-import sys
-IS_PY3 = sys.version_info[0] >= 3
-
def test_all():
"""
>>> test_all()
True
"""
- if IS_PY3:
- new_type = type(u'a',(),{})
- else:
- new_type = type('a',(),{})
+ new_type = type('a',(),{})
# Optimized tests.
assert isinstance(new_type, type)
-import sys
def test(**kw):
"""
>>> d
{'arg': 2}
"""
- if sys.version_info[0] >= 3:
- kw[u'arg'] = 3
- else:
- kw['arg'] = 3
+ kw['arg'] = 3
return kw
ctypedef long long foo
def set_longlong(long long ob, foo x, long y, val):
- tank = {}
+ cdef object tank = {}
tank[ob] = val
tank[x] = val
tank[y] = val
def f():
cdef void* p1
cdef PyObject* p2
- a = u"teststring"
+ cdef object a = u"teststring"
p1 = <void*>a
p2 = <PyObject*>a
return (<object>p1, <object>p2)
True
"""
cdef int a,b
- foo=(55,66)
- a,b=foo
+ cdef object foo = (55,66)
+ a,b = foo
return a + b