Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
0afe7a83
Commit
0afe7a83
authored
Sep 01, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests for cpdef functions and methods with optional arguments
parent
7b95089f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
0 deletions
+145
-0
tests/run/cpdef_optargs.pyx
tests/run/cpdef_optargs.pyx
+92
-0
tests/run/cpdef_optargs_pure.pxd
tests/run/cpdef_optargs_pure.pxd
+1
-0
tests/run/cpdef_optargs_pure.py
tests/run/cpdef_optargs_pure.py
+52
-0
No files found.
tests/run/cpdef_optargs.pyx
0 → 100644
View file @
0afe7a83
# mode: run
# tag: cyfunction
# cython: binding=True
cimport
cython
class
PyClass
(
object
):
a
=
2
class
PyClass99
(
object
):
a
=
99
def
pymethod
(
self
,
x
,
y
=
1
,
z
=
PyClass
):
"""
>>> obj = PyClass99()
>>> obj.pymethod(0)
(0, 1, 2)
"""
return
x
,
y
,
z
.
a
cdef
class
CyClass
:
cpdef
cpmethod
(
self
,
x
,
y
=
1
,
z
=
PyClass
):
"""
>>> obj = CyClass()
>>> obj.cpmethod(0)
(0, 1, 2)
>>> obj.cpmethod(0, 3)
(0, 3, 2)
>>> obj.cpmethod(0, 3, PyClass)
(0, 3, 2)
>>> obj.cpmethod(0, 3, 5)
Traceback (most recent call last):
AttributeError: 'int' object has no attribute 'a'
"""
return
x
,
y
,
z
.
a
y_value
=
3
p_class
=
PyClass
cpdef
cpmethod2
(
self
,
x
,
y
=
y_value
,
z
=
p_class
):
"""
>>> obj = CyClass()
>>> obj.cpmethod2(0)
(0, 3, 2)
"""
return
x
,
y
,
z
.
a
def
pymethod
(
self
,
x
,
y
=
y_value
,
z
=
p_class
):
"""
>>> obj = CyClass()
>>> obj.pymethod(0)
(0, 3, 2)
"""
return
x
,
y
,
z
.
a
# change values to check that defaults above stay unmodified
y_value
=
98
p_class
=
PyClass99
cpdef
func
(
x
,
y
=
1
,
z
=
PyClass
):
"""
>>> func(0)
(0, 1, 2)
>>> func(0, 3)
(0, 3, 2)
>>> func(0, 3, PyClass)
(0, 3, 2)
>>> func(0, 3, 5)
Traceback (most recent call last):
AttributeError: 'int' object has no attribute 'a'
"""
return
x
,
y
,
z
.
a
@
cython
.
ccall
def
pyfunc
(
x
,
y
=
1
,
z
=
PyClass
):
"""
>>> pyfunc(0)
(0, 1, 2)
>>> pyfunc(0, 3)
(0, 3, 2)
>>> pyfunc(0, 3, PyClass)
(0, 3, 2)
>>> pyfunc(0, 3, 5)
Traceback (most recent call last):
AttributeError: 'int' object has no attribute 'a'
"""
return
x
,
y
,
z
.
a
tests/run/cpdef_optargs_pure.pxd
0 → 100644
View file @
0afe7a83
cpdef
func
(
x
,
y
=*
,
z
=*
)
tests/run/cpdef_optargs_pure.py
0 → 100644
View file @
0afe7a83
# mode: run
# tag: cyfunction
# cython: binding=True
import
cython
class
PyClass
(
object
):
a
=
2
class
PyClass99
(
object
):
a
=
99
def
pymethod
(
self
,
x
,
y
=
1
,
z
=
PyClass
):
"""
>>> obj = PyClass99()
>>> obj.pymethod(0)
(0, 1, 2)
"""
return
x
,
y
,
z
.
a
def
func
(
x
,
y
=
1
,
z
=
PyClass
):
"""
>>> func(0)
(0, 1, 2)
>>> func(0, 3)
(0, 3, 2)
>>> func(0, 3, PyClass)
(0, 3, 2)
>>> func(0, 3, 5)
Traceback (most recent call last):
AttributeError: 'int' object has no attribute 'a'
"""
return
x
,
y
,
z
.
a
@
cython
.
ccall
def
pyfunc
(
x
,
y
=
1
,
z
=
PyClass
):
"""
>>> pyfunc(0)
(0, 1, 2)
>>> pyfunc(0, 3)
(0, 3, 2)
>>> pyfunc(0, 3, PyClass)
(0, 3, 2)
>>> pyfunc(0, 3, 5)
Traceback (most recent call last):
AttributeError: 'int' object has no attribute 'a'
"""
return
x
,
y
,
z
.
a
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment