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
Kirill Smelkov
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
...
@@ -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
)
{
static
PyObject
*
__Pyx_CyFunction_CallAsMethod
(
PyObject
*
func
,
PyObject
*
args
,
PyObject
*
kw
)
{
PyObject
*
result
;
PyObject
*
result
;
__pyx_CyFunctionObject
*
cyfunc
=
(
__pyx_CyFunctionObject
*
)
func
;
__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
;
Py_ssize_t
argc
;
PyObject
*
new_args
;
PyObject
*
new_args
;
PyObject
*
self
;
PyObject
*
self
;
...
...
tests/run/classmethod.pyx
View file @
66ca26c4
__doc__
=
u"""
__doc__
=
u"""
>>> class1.view()
class1
>>> class1.plus(1)
>>> class1.plus(1)
6
6
>>> class1.view()
class1
>>> class1().view()
class1
>>> class1.bview()
class1
>>> class1().bview()
class1
>>> class2.view()
>>> class2.view()
class2
class2
>>> class2.plus(1)
>>> class2.plus(1)
7
7
>>> class3.view()
>>> class3.view()
class3
class3
>>> class3.bview()
class3
>>> class3().bview()
class3
>>> class3.plus(1)
>>> class3.plus(1)
8
8
>>> class4.view()
>>> class4.view()
class4
class4
>>> class5.view()
>>> class5.view()
class5
class5
"""
"""
cimport
cython
def
f_plus
(
cls
,
a
):
def
f_plus
(
cls
,
a
):
return
cls
.
a
+
a
return
cls
.
a
+
a
class
class1
:
class
class1
:
a
=
5
a
=
5
plus
=
classmethod
(
f_plus
)
plus
=
classmethod
(
f_plus
)
...
@@ -27,6 +43,12 @@ class class1:
...
@@ -27,6 +43,12 @@ class class1:
print
cls
.
__name__
print
cls
.
__name__
view
=
classmethod
(
view
)
view
=
classmethod
(
view
)
@
classmethod
@
cython
.
binding
(
True
)
def
bview
(
cls
):
print
cls
.
__name__
class
class2
(
object
):
class
class2
(
object
):
a
=
6
a
=
6
plus
=
classmethod
(
f_plus
)
plus
=
classmethod
(
f_plus
)
...
@@ -34,6 +56,7 @@ class class2(object):
...
@@ -34,6 +56,7 @@ class class2(object):
print
cls
.
__name__
print
cls
.
__name__
view
=
classmethod
(
view
)
view
=
classmethod
(
view
)
cdef
class
class3
:
cdef
class
class3
:
a
=
7
a
=
7
plus
=
classmethod
(
f_plus
)
plus
=
classmethod
(
f_plus
)
...
@@ -41,10 +64,17 @@ cdef class class3:
...
@@ -41,10 +64,17 @@ cdef class class3:
print
cls
.
__name__
print
cls
.
__name__
view
=
classmethod
(
view
)
view
=
classmethod
(
view
)
@
classmethod
@
cython
.
binding
(
True
)
def
bview
(
cls
):
print
cls
.
__name__
class
class4
:
class
class4
:
@
classmethod
@
classmethod
def
view
(
cls
):
def
view
(
cls
):
print
cls
.
__name__
print
cls
.
__name__
class
class5
(
class4
):
class
class5
(
class4
):
pass
pass
tests/run/staticmethod.pyx
View file @
66ca26c4
...
@@ -7,8 +7,16 @@ __doc__ = u"""
...
@@ -7,8 +7,16 @@ __doc__ = u"""
2
2
>>> class4.plus1(1)
>>> class4.plus1(1)
2
2
>>> class4().plus1(1)
2
>>> class4.bplus1(1)
2
>>> class4().bplus1(1)
2
"""
"""
cimport
cython
def
f_plus
(
a
):
def
f_plus
(
a
):
return
a
+
1
return
a
+
1
...
@@ -26,6 +34,12 @@ class class4:
...
@@ -26,6 +34,12 @@ class class4:
def
plus1
(
a
):
def
plus1
(
a
):
return
a
+
1
return
a
+
1
@
staticmethod
@
cython
.
binding
(
True
)
def
bplus1
(
a
):
return
a
+
1
def
nested_class
():
def
nested_class
():
"""
"""
>>> cls = nested_class()
>>> cls = nested_class()
...
@@ -44,6 +58,7 @@ def nested_class():
...
@@ -44,6 +58,7 @@ def nested_class():
return
a
+
1
return
a
+
1
return
class5
return
class5
cdef
class
BaseClass
(
object
):
cdef
class
BaseClass
(
object
):
"""
"""
Test cdef static methods with super() and Python subclasses
Test cdef static methods with super() and Python subclasses
...
@@ -64,9 +79,11 @@ cdef class BaseClass(object):
...
@@ -64,9 +79,11 @@ cdef class BaseClass(object):
print
arg1
print
arg1
@
staticmethod
@
staticmethod
@
cython
.
binding
(
True
)
def
mystaticmethod2
(
a
,
b
,
c
):
def
mystaticmethod2
(
a
,
b
,
c
):
print
a
,
b
,
c
print
a
,
b
,
c
cdef
class
SubClass
(
BaseClass
):
cdef
class
SubClass
(
BaseClass
):
"""
"""
>>> obj = SubClass()
>>> obj = SubClass()
...
@@ -83,6 +100,7 @@ cdef class SubClass(BaseClass):
...
@@ -83,6 +100,7 @@ cdef class SubClass(BaseClass):
print
arg1
print
arg1
super
().
mystaticmethod
(
self
,
arg1
+
1
)
super
().
mystaticmethod
(
self
,
arg1
+
1
)
class
SubSubClass
(
SubClass
):
class
SubSubClass
(
SubClass
):
"""
"""
>>> obj = SubSubClass()
>>> obj = SubSubClass()
...
@@ -121,6 +139,7 @@ cdef class ArgsKwargs(object):
...
@@ -121,6 +139,7 @@ cdef class ArgsKwargs(object):
"""
"""
return
args
+
tuple
(
sorted
(
kwargs
.
items
()))
return
args
+
tuple
(
sorted
(
kwargs
.
items
()))
class
StaticmethodSubclass
(
staticmethod
):
class
StaticmethodSubclass
(
staticmethod
):
"""
"""
>>> s = StaticmethodSubclass(None)
>>> 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