Author: Ronan Lamy <[email protected]>
Branch: 
Changeset: r93004:3b8c612bb506
Date: 2017-11-13 18:14 +0000
http://bitbucket.org/pypy/pypy/changeset/3b8c612bb506/

Log:    Test an obscure difference between C-defined and Python-defined
        functions

diff --git a/pypy/module/cpyext/test/test_methodobject.py 
b/pypy/module/cpyext/test/test_methodobject.py
--- a/pypy/module/cpyext/test/test_methodobject.py
+++ b/pypy/module/cpyext/test/test_methodobject.py
@@ -93,6 +93,22 @@
             assert mod.isSameFunction(mod.getarg_O)
         raises(SystemError, mod.isSameFunction, 1)
 
+    def test_function_as_method(self):
+        # Unlike user functions, builtins don't become methods
+        mod = self.import_extension('foo', [
+            ('f', 'METH_NOARGS',
+            '''
+                return PyLong_FromLong(42);
+            '''),
+            ])
+        class A(object): pass
+        A.f = mod.f
+        A.g = lambda: 42
+        assert A.f() == 42
+        raises(TypeError, A.g)
+        assert A().f() == 42
+        raises(TypeError, A().g)
+
     def test_check(self):
         mod = self.import_extension('foo', [
             ('check', 'METH_O',
@@ -116,4 +132,3 @@
         assert mod.check(A) == 0
         assert mod.check(A.meth) == 0
         assert mod.check(A.stat) == 0
- 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to