Author: Armin Rigo <[email protected]>
Branch:
Changeset: r94525:5d5b4b989e7b
Date: 2018-05-12 08:51 +0200
http://bitbucket.org/pypy/pypy/changeset/5d5b4b989e7b/
Log: Issue #2818
__module__ attribute should be writable on cpyext built-in functions
diff --git a/pypy/module/cpyext/methodobject.py
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -142,6 +142,17 @@
else:
return space.w_None
+ def fget_module(self, space):
+ if self.w_module is None:
+ return space.w_None
+ return self.w_module
+
+ def fset_module(self, space, w_module):
+ self.w_module = w_module
+
+ def fdel_module(self, space):
+ self.w_module = space.w_None
+
class W_PyCMethodObject(W_PyCFunctionObject):
def __init__(self, space, ml, w_type):
@@ -305,7 +316,9 @@
'builtin_function_or_method',
__call__ = interp2app(W_PyCFunctionObject.descr_call),
__doc__ = GetSetProperty(W_PyCFunctionObject.get_doc),
- __module__ = interp_attrproperty_w('w_module', cls=W_PyCFunctionObject),
+ __module__ = GetSetProperty(W_PyCFunctionObject.fget_module,
+ W_PyCFunctionObject.fset_module,
+ W_PyCFunctionObject.fdel_module),
__name__ = interp_attrproperty('name', cls=W_PyCFunctionObject,
wrapfn="newtext_or_none"),
)
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
@@ -192,3 +192,17 @@
assert mod.check(A) == 0
assert mod.check(A.meth) == 0
assert mod.check(A.stat) == 0
+
+ def test_module_attribute(self):
+ mod = self.import_extension('MyModule', [
+ ('getarg_NO', 'METH_NOARGS',
+ '''
+ Py_INCREF(Py_None);
+ return Py_None;
+ '''
+ ),
+ ])
+ assert mod.getarg_NO() is None
+ assert mod.getarg_NO.__module__ == 'MyModule'
+ mod.getarg_NO.__module__ = 'foobar'
+ assert mod.getarg_NO.__module__ == 'foobar'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit