[Python-checkins] r73006 - in python/trunk: Lib/test/test_funcattrs.py Misc/NEWS Objects/funcobject.c
raymond.hettinger
python-checkins at python.org
Fri May 29 06:58:53 CEST 2009
Author: raymond.hettinger
Date: Fri May 29 06:58:52 2009
New Revision: 73006
Log:
Issue 5982: Classmethod and staticmethod expose wrapped function with __func__.
Modified:
python/trunk/Lib/test/test_funcattrs.py
python/trunk/Misc/NEWS
python/trunk/Objects/funcobject.c
Modified: python/trunk/Lib/test/test_funcattrs.py
==============================================================================
--- python/trunk/Lib/test/test_funcattrs.py (original)
+++ python/trunk/Lib/test/test_funcattrs.py Fri May 29 06:58:52 2009
@@ -273,10 +273,23 @@
self.assertEqual(self.b.__doc__, None)
self.assertEqual(self.b.func_doc, None)
+class StaticMethodAttrsTest(unittest.TestCase):
+ def test_func_attribute(self):
+ def f():
+ pass
+
+ c = classmethod(f)
+ self.assert_(c.__func__ is f)
+
+ s = staticmethod(f)
+ self.assert_(s.__func__ is f)
+
+
def test_main():
test_support.run_unittest(FunctionPropertiesTest, ImplicitReferencesTest,
ArbitraryFunctionAttrTest, FunctionDictsTest,
- FunctionDocstringTest)
+ FunctionDocstringTest,
+ StaticMethodAttrsTest)
if __name__ == "__main__":
test_main()
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Fri May 29 06:58:52 2009
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- Issue #5982: staticmethod and classmethod now expose the wrapped
+ function with __func__.
+
- Added support for multiple context managers in the same with-statement.
Deprecated contextlib.nested() which is no longer needed.
Modified: python/trunk/Objects/funcobject.c
==============================================================================
--- python/trunk/Objects/funcobject.c (original)
+++ python/trunk/Objects/funcobject.c Fri May 29 06:58:52 2009
@@ -669,6 +669,11 @@
return 0;
}
+static PyMemberDef cm_memberlist[] = {
+ {"__func__", T_OBJECT, offsetof(classmethod, cm_callable), READONLY},
+ {NULL} /* Sentinel */
+};
+
PyDoc_STRVAR(classmethod_doc,
"classmethod(function) -> method\n\
\n\
@@ -719,7 +724,7 @@
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
- 0, /* tp_members */
+ cm_memberlist, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
@@ -819,6 +824,11 @@
return 0;
}
+static PyMemberDef sm_memberlist[] = {
+ {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY},
+ {NULL} /* Sentinel */
+};
+
PyDoc_STRVAR(staticmethod_doc,
"staticmethod(function) -> method\n\
\n\
@@ -866,7 +876,7 @@
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
- 0, /* tp_members */
+ sm_memberlist, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
More information about the Python-checkins
mailing list