Skip to content

classmethod, staticmethod: expose wrapped function #50232

Closed

Description

@gsakkis
mannequin
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']

    Activity

    1. gsakkis commented on May 9, 2009

      gsakkismannequin
      MannequinAuthor

      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

    2. added
      type-feature
      on May 9, 2009
    3. self-assigned this
      on May 11, 2009
    4. terryjreedy commented on May 15, 2009

      @terryjreedy
      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.

    5. gsakkis commented on May 19, 2009

      gsakkismannequin
      MannequinAuthor

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

    6. rhettinger commented on May 20, 2009

      @rhettinger
      Contributor

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

    7. removed their assignment
      on May 20, 2009
    8. amauryfa commented on May 20, 2009

      @amauryfa
      Contributor

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

    9. rhettinger commented on May 29, 2009

      @rhettinger
      Contributor

      r73005 and r73006

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    type-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions