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
f95c9c5c
Commit
f95c9c5c
authored
Oct 01, 2019
by
da-woods
Committed by
Stefan Behnel
Jan 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix and move tests for functions used as methods (GH-3159)
parent
9c2eeb0e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
30 deletions
+80
-30
tests/run/function_as_method_T494.pyx
tests/run/function_as_method_T494.pyx
+36
-0
tests/run/function_as_method_py_T494.py
tests/run/function_as_method_py_T494.py
+32
-0
tests/run/staticmethod.pyx
tests/run/staticmethod.pyx
+12
-30
No files found.
tests/run/function_as_method_T494.pyx
View file @
f95c9c5c
...
...
@@ -12,3 +12,39 @@ class A:
def
foo
(
self
):
return
self
is
not
None
# assignment of functions used in a "static method" type way behaves differently
# in Python2 and 3
import
sys
if
sys
.
version_info
[
0
]
==
2
:
__doc__
=
""">>> B.plus1(1) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
TypeError: unbound
"""
else
:
__doc__
=
""">>> B.plus1(1)
2
"""
# with binding==False assignment of functions always worked - doesn't match Python
# behaviour but ensures Cython behaviour stays consistent
__doc__
+=
"""
>>> B.plus1_nobind(1)
2
"""
cimport
cython
def
f_plus
(
a
):
return
a
+
1
@
cython
.
binding
(
False
)
def
f_plus_nobind
(
a
):
return
a
+
1
cdef
class
B
:
plus1
=
f_plus
plus1_nobind
=
f_plus_nobind
tests/run/function_as_method_py_T494.py
View file @
f95c9c5c
...
...
@@ -11,3 +11,35 @@ class A:
def
foo
(
self
):
return
self
is
not
None
# assignment of functions used in a "static method" type way behaves differently
# in Python2 and 3
import
sys
if
sys
.
version_info
[
0
]
==
2
:
__doc__
=
u"""
>>> B.plus1(1) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
TypeError: unbound
>>> C.plus1(1) #doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
...
TypeError: unbound
"""
else
:
__doc__
=
u"""
>>> B.plus1(1)
2
>>> C.plus1(1)
2
"""
def
f_plus
(
a
):
return
a
+
1
class
B
:
plus1
=
f_plus
class
C
(
object
):
plus1
=
f_plus
tests/run/staticmethod.pyx
View file @
f95c9c5c
__doc__
=
u"""
>>> class1.plus1(1)
2
>>> class2.plus1(1)
2
>>> class3.plus1(1)
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
class
class1
:
plus1
=
f_plus
class
class2
(
object
):
plus1
=
f_plus
cdef
class
class3
:
plus1
=
f_plus
class
class4
:
u"""
>>> class1.plus1(1)
2
>>> class1().plus1(1)
2
>>> class1.bplus1(1)
2
>>> class1().bplus1(1)
2
"""
@
staticmethod
def
plus1
(
a
):
return
a
+
1
...
...
@@ -49,14 +31,14 @@ def nested_class():
>>> obj.plus1(1)
2
"""
class
class
5
(
object
):
class
class
2
(
object
):
def
__new__
(
cls
):
# implicit staticmethod
return
object
.
__new__
(
cls
)
@
staticmethod
def
plus1
(
a
):
return
a
+
1
return
class
5
return
class
2
cdef
class
BaseClass
(
object
):
...
...
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