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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
66ca26c4
Commit
66ca26c4
authored
Sep 03, 2016
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repair CyFunction behaviour for staticmethods and add tests for classmethods
parent
0bc33758
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
3 deletions
+52
-3
Cython/Utility/CythonFunction.c
Cython/Utility/CythonFunction.c
+1
-1
tests/run/classmethod.pyx
tests/run/classmethod.pyx
+32
-2
tests/run/staticmethod.pyx
tests/run/staticmethod.pyx
+19
-0
No files found.
Cython/Utility/CythonFunction.c
View file @
66ca26c4
...
...
@@ -630,7 +630,7 @@ static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *a
static
PyObject
*
__Pyx_CyFunction_CallAsMethod
(
PyObject
*
func
,
PyObject
*
args
,
PyObject
*
kw
)
{
PyObject
*
result
;
__pyx_CyFunctionObject
*
cyfunc
=
(
__pyx_CyFunctionObject
*
)
func
;
if
(
cyfunc
->
flags
&
__Pyx_CYFUNCTION_CCLASS
)
{
if
(
(
cyfunc
->
flags
&
__Pyx_CYFUNCTION_CCLASS
)
&&
!
(
cyfunc
->
flags
&
__Pyx_CYFUNCTION_STATICMETHOD
)
)
{
Py_ssize_t
argc
;
PyObject
*
new_args
;
PyObject
*
self
;
...
...
tests/run/classmethod.pyx
View file @
66ca26c4
__doc__
=
u"""
>>> class1.view()
class1
>>> class1.plus(1)
6
>>> class1.view()
class1
>>> class1().view()
class1
>>> class1.bview()
class1
>>> class1().bview()
class1
>>> class2.view()
class2
>>> class2.plus(1)
7
>>> class3.view()
class3
>>> class3.bview()
class3
>>> class3().bview()
class3
>>> class3.plus(1)
8
>>> class4.view()
class4
>>> class5.view()
class5
"""
cimport
cython
def
f_plus
(
cls
,
a
):
return
cls
.
a
+
a
class
class1
:
a
=
5
plus
=
classmethod
(
f_plus
)
...
...
@@ -27,6 +43,12 @@ class class1:
print
cls
.
__name__
view
=
classmethod
(
view
)
@
classmethod
@
cython
.
binding
(
True
)
def
bview
(
cls
):
print
cls
.
__name__
class
class2
(
object
):
a
=
6
plus
=
classmethod
(
f_plus
)
...
...
@@ -34,6 +56,7 @@ class class2(object):
print
cls
.
__name__
view
=
classmethod
(
view
)
cdef
class
class3
:
a
=
7
plus
=
classmethod
(
f_plus
)
...
...
@@ -41,10 +64,17 @@ cdef class class3:
print
cls
.
__name__
view
=
classmethod
(
view
)
@
classmethod
@
cython
.
binding
(
True
)
def
bview
(
cls
):
print
cls
.
__name__
class
class4
:
@
classmethod
def
view
(
cls
):
print
cls
.
__name__
class
class5
(
class4
):
pass
tests/run/staticmethod.pyx
View file @
66ca26c4
...
...
@@ -7,8 +7,16 @@ __doc__ = u"""
2
>>> class4.plus1(1)
2
>>> class4().plus1(1)
2
>>> class4.bplus1(1)
2
>>> class4().bplus1(1)
2
"""
cimport
cython
def
f_plus
(
a
):
return
a
+
1
...
...
@@ -26,6 +34,12 @@ class class4:
def
plus1
(
a
):
return
a
+
1
@
staticmethod
@
cython
.
binding
(
True
)
def
bplus1
(
a
):
return
a
+
1
def
nested_class
():
"""
>>> cls = nested_class()
...
...
@@ -44,6 +58,7 @@ def nested_class():
return
a
+
1
return
class5
cdef
class
BaseClass
(
object
):
"""
Test cdef static methods with super() and Python subclasses
...
...
@@ -64,9 +79,11 @@ cdef class BaseClass(object):
print
arg1
@
staticmethod
@
cython
.
binding
(
True
)
def
mystaticmethod2
(
a
,
b
,
c
):
print
a
,
b
,
c
cdef
class
SubClass
(
BaseClass
):
"""
>>> obj = SubClass()
...
...
@@ -83,6 +100,7 @@ cdef class SubClass(BaseClass):
print
arg1
super
().
mystaticmethod
(
self
,
arg1
+
1
)
class
SubSubClass
(
SubClass
):
"""
>>> obj = SubSubClass()
...
...
@@ -121,6 +139,7 @@ cdef class ArgsKwargs(object):
"""
return
args
+
tuple
(
sorted
(
kwargs
.
items
()))
class
StaticmethodSubclass
(
staticmethod
):
"""
>>> s = StaticmethodSubclass(None)
...
...
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