Commit a152462e authored by Jeroen Demeyer's avatar Jeroen Demeyer

In Python 3, an unbound method is just the function

parent 969dbad1
...@@ -617,7 +617,7 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { ...@@ -617,7 +617,7 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) {
#endif #endif
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
#define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func)) #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : (Py_INCREF(func), func))
#else #else
#define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass) #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif #endif
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# tag: cyfunction # tag: cyfunction
import sys import sys
IS_PY2 = sys.version_info[0] < 3
IS_PY3 = sys.version_info[0] >= 3 IS_PY3 = sys.version_info[0] >= 3
IS_PY34 = sys.version_info > (3, 4, 0, 'beta', 3) IS_PY34 = sys.version_info > (3, 4, 0, 'beta', 3)
...@@ -348,3 +349,21 @@ cdef class TestDecoratedMethods: ...@@ -348,3 +349,21 @@ cdef class TestDecoratedMethods:
2 2
""" """
return x return x
cdef class TestUnboundMethodCdef:
"""
>>> C = TestUnboundMethodCdef
>>> IS_PY2 or (C.meth is C.__dict__["meth"])
True
"""
def meth(self): pass
class TestUnboundMethod:
"""
>>> C = TestUnboundMethod
>>> IS_PY2 or (C.meth is C.__dict__["meth"])
True
"""
def meth(self): pass
import sys
IS_PY2 = sys.version_info[0] < 3
import cython import cython
is_compiled = cython.compiled is_compiled = cython.compiled
...@@ -360,3 +363,12 @@ class CClass(object): ...@@ -360,3 +363,12 @@ class CClass(object):
def get_attr(self): def get_attr(self):
print(cython.typeof(self.attr)) print(cython.typeof(self.attr))
return self.attr return self.attr
class TestUnboundMethod:
"""
>>> C = TestUnboundMethod
>>> IS_PY2 or (C.meth is C.__dict__["meth"])
True
"""
def meth(self): pass
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment