Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

classmethod, staticmethod: expose wrapped function #50232

Closed
gsakkis mannequin opened this issue May 9, 2009 · 6 comments
Closed

classmethod, staticmethod: expose wrapped function #50232

gsakkis mannequin opened this issue May 9, 2009 · 6 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@gsakkis
Copy link
Mannequin

gsakkis mannequin commented May 9, 2009

BPO 5982
Nosy @rhettinger, @terryjreedy, @amauryfa
Files
  • staticmethod_func.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/amauryfa'
    closed_at = <Date 2009-05-29.05:00:53.249>
    created_at = <Date 2009-05-09.21:05:02.218>
    labels = ['type-feature']
    title = 'classmethod, staticmethod: expose wrapped function'
    updated_at = <Date 2009-05-29.05:00:52.686>
    user = 'https://bugs.python.org/gsakkis'

    bugs.python.org fields:

    activity = <Date 2009-05-29.05:00:52.686>
    actor = 'rhettinger'
    assignee = 'amaury.forgeotdarc'
    closed = True
    closed_date = <Date 2009-05-29.05:00:53.249>
    closer = 'rhettinger'
    components = []
    creation = <Date 2009-05-09.21:05:02.218>
    creator = 'gsakkis'
    dependencies = []
    files = ['14021']
    hgrepos = []
    issue_num = 5982
    keywords = ['patch']
    message_count = 6.0
    messages = ['87511', '87839', '88101', '88102', '88109', '88498']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'terry.reedy', 'amaury.forgeotdarc', 'gsakkis']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue5982'
    versions = ['Python 2.7', 'Python 3.2']

    @gsakkis
    Copy link
    Mannequin Author

    gsakkis mannequin commented May 9, 2009

    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

    @gsakkis gsakkis mannequin added the type-feature A feature request or enhancement label May 9, 2009
    @rhettinger rhettinger self-assigned this May 11, 2009
    @terryjreedy
    Copy link
    Member

    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.

    @gsakkis
    Copy link
    Mannequin Author

    gsakkis mannequin commented May 19, 2009

    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".

    @rhettinger
    Copy link
    Contributor

    I am all for exposing the __func__ directly but don't immediately see
    how to do it.

    @rhettinger rhettinger removed their assignment May 20, 2009
    @amauryfa
    Copy link
    Member

    Is there a difficulty I did not see? Here is a patch.

    @rhettinger
    Copy link
    Contributor

    r73005 and r73006

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants