[Python-checkins] r73005 - in python/branches/py3k: Lib/test/test_funcattrs.py Misc/NEWS Objects/funcobject.c
raymond.hettinger
python-checkins at python.org
Fri May 29 06:52:28 CEST 2009
Author: raymond.hettinger
Date: Fri May 29 06:52:27 2009
New Revision: 73005
Log:
Issue 5982: Classmethod and staticmethod expose wrapped function with __func__.
Modified:
python/branches/py3k/Lib/test/test_funcattrs.py
python/branches/py3k/Misc/NEWS
python/branches/py3k/Objects/funcobject.c
Modified: python/branches/py3k/Lib/test/test_funcattrs.py
==============================================================================
--- python/branches/py3k/Lib/test/test_funcattrs.py (original)
+++ python/branches/py3k/Lib/test/test_funcattrs.py Fri May 29 06:52:27 2009
@@ -254,11 +254,23 @@
self.assert_(cell(-36) == cell(-36.0))
self.assert_(cell(True) > empty_cell())
+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():
support.run_unittest(FunctionPropertiesTest, ImplicitReferencesTest,
ArbitraryFunctionAttrTest, FunctionDictsTest,
- FunctionDocstringTest, CellTest)
+ FunctionDocstringTest, CellTest,
+ StaticMethodAttrsTest)
if __name__ == "__main__":
test_main()
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Fri May 29 06:52:27 2009
@@ -15,6 +15,9 @@
- Issue #6089: Fixed str.format with certain invalid field specifiers
that would raise SystemError.
+- 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/branches/py3k/Objects/funcobject.c
==============================================================================
--- python/branches/py3k/Objects/funcobject.c (original)
+++ python/branches/py3k/Objects/funcobject.c Fri May 29 06:52:27 2009
@@ -775,6 +775,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\
@@ -825,7 +830,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 */
@@ -925,6 +930,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\
@@ -972,7 +982,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