Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
2bcde144
Commit
2bcde144
authored
May 29, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 5982: Classmethod and staticmethod expose wrapped function with __func__.
parent
ebe99ab3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
3 deletions
+28
-3
Lib/test/test_funcattrs.py
Lib/test/test_funcattrs.py
+13
-1
Misc/NEWS
Misc/NEWS
+3
-0
Objects/funcobject.c
Objects/funcobject.c
+12
-2
No files found.
Lib/test/test_funcattrs.py
View file @
2bcde144
...
...
@@ -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
()
Misc/NEWS
View file @
2bcde144
...
...
@@ -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.
...
...
Objects/funcobject.c
View file @
2bcde144
...
...
@@ -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 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment