diff options
| author | Raymond Hettinger <python@rcn.com> | 2009-05-29 04:52:27 +0000 | 
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2009-05-29 04:52:27 +0000 | 
| commit | 2bcde144ae79c72de05196f7da4ed32396e398d6 (patch) | |
| tree | 290c3629ef6f8d99dc59a0d0dadafdfb353efca6 | |
| parent | ebe99ab34444d911c6594d07de81966592cc9e85 (diff) | |
| download | cpython-git-2bcde144ae79c72de05196f7da4ed32396e398d6.tar.gz | |
Issue 5982: Classmethod and staticmethod expose wrapped function with __func__.
| -rw-r--r-- | Lib/test/test_funcattrs.py | 14 | ||||
| -rw-r--r-- | Misc/NEWS | 3 | ||||
| -rw-r--r-- | Objects/funcobject.c | 14 | 
3 files changed, 28 insertions, 3 deletions
diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index 5e47d6bf86..b42f6cc4be 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -254,11 +254,23 @@ class CellTest(unittest.TestCase):          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() @@ -15,6 +15,9 @@ Core and Builtins  - 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. diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 1bb2092d66..acd662cb32 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -775,6 +775,11 @@ cm_init(PyObject *self, PyObject *args, PyObject *kwds)  	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 @@ PyTypeObject PyClassMethod_Type = {  	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 @@ sm_init(PyObject *self, PyObject *args, PyObject *kwds)  	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 @@ PyTypeObject PyStaticMethod_Type = {  	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 */  | 
