Created on 2009-05-09 21:05 by gsakkis, last changed 2022-04-11 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| staticmethod_func.patch | amaury.forgeotdarc, 2009-05-20 09:29 | |||
| Messages (6) | |||
|---|---|---|---|
| msg87511 - (view) | Author: George Sakkis (gsakkis) | Date: 2009-05-09 21:05 | |
It would be nice if classmethod/staticmethod exposed the wrapped function as a read-only attribute/property. Currently the function can be retrieved indirectly but it's obscure (and perhaps not always correct, I'm not sure): In [147]: def f():pass .....: In [148]: c = classmethod(f) In [149]: s = staticmethod(f) In [150]: c.__get__(1).im_func is f Out[150]: True In [151]: s.__get__(1) is f Out[151]: True |
|||
| msg87839 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2009-05-15 20:48 | |
Having to bind and unbind a classmethod to get at the function is definitely a bit weird, and also susceptible to changing implementation, but do you have a practical use case to motivate the effort needed? In Py3, '__func__' replaced 'im_func', and that is the name to use if the attribute is added. A change in 3.2 is at least as likely as a change in 2.7. |
|||
| msg88101 - (view) | Author: George Sakkis (gsakkis) | Date: 2009-05-19 23:25 | |
I don't remember the exact use case but it had to do with making a decorator robust enough to work for different kinds of callables (and a few common non-callables such as classmethod/staticmethod). It's not a show stopper by any means but I thought it would be easy (if not trivial) to implement, and regardless of actual use cases I don't see a reason to keep the function "hidden". |
|||
| msg88102 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2009-05-20 01:27 | |
I am all for exposing the __func__ directly but don't immediately see how to do it. |
|||
| msg88109 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * ![]() |
Date: 2009-05-20 09:29 | |
Is there a difficulty I did not see? Here is a patch. |
|||
| msg88498 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2009-05-29 05:00 | |
r73005 and r73006 |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:56:48 | admin | set | github: 50232 |
| 2009-05-29 05:00:53 | rhettinger | set | status: open -> closed messages: + msg88498 |
| 2009-05-20 17:48:15 | rhettinger | set | assignee: amaury.forgeotdarc resolution: accepted |
| 2009-05-20 09:29:19 | amaury.forgeotdarc | set | files:
+ staticmethod_func.patch nosy:
+ amaury.forgeotdarc keywords: + patch |
| 2009-05-20 01:27:34 | rhettinger | set | assignee: rhettinger -> (no value) messages: + msg88102 |
| 2009-05-19 23:25:09 | gsakkis | set | messages: + msg88101 |
| 2009-05-15 20:48:53 | terry.reedy | set | nosy:
+ terry.reedy messages:
+ msg87839 |
| 2009-05-11 20:37:57 | rhettinger | set | assignee: rhettinger nosy: + rhettinger |
| 2009-05-09 21:05:02 | gsakkis | create | |
