Blame tests/run/cpdef_optargs.pyx
|
Packit Service |
99d393 |
# mode: run
|
|
Packit Service |
99d393 |
# tag: cyfunction
|
|
Packit Service |
99d393 |
# cython: binding=True
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
cimport cython
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
class PyClass(object):
|
|
Packit Service |
99d393 |
a = 2
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
class PyClass99(object):
|
|
Packit Service |
99d393 |
a = 99
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
def pymethod(self, x, y=1, z=PyClass):
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
>>> obj = PyClass99()
|
|
Packit Service |
99d393 |
>>> obj.pymethod(0)
|
|
Packit Service |
99d393 |
(0, 1, 2)
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
return x, y, z.a
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
cdef class CyClass:
|
|
Packit Service |
99d393 |
cpdef cpmethod(self, x, y=1, z=PyClass):
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
>>> obj = CyClass()
|
|
Packit Service |
99d393 |
>>> obj.cpmethod(0)
|
|
Packit Service |
99d393 |
(0, 1, 2)
|
|
Packit Service |
99d393 |
>>> obj.cpmethod(0, 3)
|
|
Packit Service |
99d393 |
(0, 3, 2)
|
|
Packit Service |
99d393 |
>>> obj.cpmethod(0, 3, PyClass)
|
|
Packit Service |
99d393 |
(0, 3, 2)
|
|
Packit Service |
99d393 |
>>> obj.cpmethod(0, 3, 5)
|
|
Packit Service |
99d393 |
Traceback (most recent call last):
|
|
Packit Service |
99d393 |
AttributeError: 'int' object has no attribute 'a'
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
return x, y, z.a
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
y_value = 3
|
|
Packit Service |
99d393 |
p_class = PyClass
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
cpdef cpmethod2(self, x, y=y_value, z=p_class):
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
>>> obj = CyClass()
|
|
Packit Service |
99d393 |
>>> obj.cpmethod2(0)
|
|
Packit Service |
99d393 |
(0, 3, 2)
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
return x, y, z.a
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
def pymethod(self, x, y=y_value, z=p_class):
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
>>> obj = CyClass()
|
|
Packit Service |
99d393 |
>>> obj.pymethod(0)
|
|
Packit Service |
99d393 |
(0, 3, 2)
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
return x, y, z.a
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
# change values to check that defaults above stay unmodified
|
|
Packit Service |
99d393 |
y_value = 98
|
|
Packit Service |
99d393 |
p_class = PyClass99
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
cpdef func(x, y=1, z=PyClass):
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
>>> func(0)
|
|
Packit Service |
99d393 |
(0, 1, 2)
|
|
Packit Service |
99d393 |
>>> func(0, 3)
|
|
Packit Service |
99d393 |
(0, 3, 2)
|
|
Packit Service |
99d393 |
>>> func(0, 3, PyClass)
|
|
Packit Service |
99d393 |
(0, 3, 2)
|
|
Packit Service |
99d393 |
>>> func(0, 3, 5)
|
|
Packit Service |
99d393 |
Traceback (most recent call last):
|
|
Packit Service |
99d393 |
AttributeError: 'int' object has no attribute 'a'
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
return x, y, z.a
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
|
|
Packit Service |
99d393 |
@cython.ccall
|
|
Packit Service |
99d393 |
def pyfunc(x, y=1, z=PyClass):
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
>>> pyfunc(0)
|
|
Packit Service |
99d393 |
(0, 1, 2)
|
|
Packit Service |
99d393 |
>>> pyfunc(0, 3)
|
|
Packit Service |
99d393 |
(0, 3, 2)
|
|
Packit Service |
99d393 |
>>> pyfunc(0, 3, PyClass)
|
|
Packit Service |
99d393 |
(0, 3, 2)
|
|
Packit Service |
99d393 |
>>> pyfunc(0, 3, 5)
|
|
Packit Service |
99d393 |
Traceback (most recent call last):
|
|
Packit Service |
99d393 |
AttributeError: 'int' object has no attribute 'a'
|
|
Packit Service |
99d393 |
"""
|
|
Packit Service |
99d393 |
return x, y, z.a
|