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

recursive_repr forgets to override __qualname__ of wrapper #70821

Closed
zhangyangyu opened this issue Mar 24, 2016 · 5 comments
Closed

recursive_repr forgets to override __qualname__ of wrapper #70821

zhangyangyu opened this issue Mar 24, 2016 · 5 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@zhangyangyu
Copy link
Member

BPO 26634
Nosy @rhettinger, @serhiy-storchaka, @zhangyangyu
Files
  • qualname_of_recursive_repr_in_reprlib.patch
  • qualname_of_recursive_repr_in_reprlib_v2.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/serhiy-storchaka'
    closed_at = <Date 2016-04-26.06:32:05.471>
    created_at = <Date 2016-03-24.04:09:36.638>
    labels = ['type-bug', 'library']
    title = 'recursive_repr forgets to override __qualname__ of wrapper'
    updated_at = <Date 2016-04-26.06:32:05.470>
    user = 'https://github.com/zhangyangyu'

    bugs.python.org fields:

    activity = <Date 2016-04-26.06:32:05.470>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-04-26.06:32:05.471>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2016-03-24.04:09:36.638>
    creator = 'xiang.zhang'
    dependencies = []
    files = ['42266', '42268']
    hgrepos = []
    issue_num = 26634
    keywords = ['patch']
    message_count = 5.0
    messages = ['262326', '262327', '262329', '264048', '264218']
    nosy_count = 4.0
    nosy_names = ['rhettinger', 'python-dev', 'serhiy.storchaka', 'xiang.zhang']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'commit review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26634'
    versions = ['Python 3.5', 'Python 3.6']

    @zhangyangyu
    Copy link
    Member Author

    In reprlib.recursive_repr, it seems __qualname__ is forgotten. Giving the example in reprlib document, it gives a strange result 'recursive_repr.<locals>.decorating_function.<locals>.wrapper' of Mylist.__repr__.__qualname__.

    I simply add the assignment of __qualname__. But I doubt the treatment of __module__, __doc__, __name__, __qualname__ will raise AttributeError when they don't exist in user_function. Is this the desired behaviour or we'd better treat them like functools.update_wrapper, catch and then ignore the error.

    @zhangyangyu zhangyangyu added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 24, 2016
    @rhettinger
    Copy link
    Contributor

    FWIW, qualname was invented *after* recursive_repr, so it would be more accurate to say that qualname forgot recursive_repr :-)

    If you don't mind, please add a test to your patch.

    @rhettinger rhettinger self-assigned this Mar 24, 2016
    @zhangyangyu
    Copy link
    Member Author

    Hi, Raymond, I've added the test to test the assigned attributes.
    I use WRAPPER_ASSIGNMENTS in functools so we can keep them consistent. I don't know how to get the original func from the already decorated methods in this case so I define a new container.
    If there are mistakes or better solution, I am willing to know.

    @serhiy-storchaka
    Copy link
    Member

    LGTM. I would commit the patch to 3.5 too.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 26, 2016

    New changeset 1f0369547b0e by Serhiy Storchaka in branch '3.5':
    Issue bpo-26634: recursive_repr() now sets __qualname__ of wrapper.
    https://hg.python.org/cpython/rev/1f0369547b0e

    New changeset fb70ea8b7b2d by Serhiy Storchaka in branch 'default':
    Issue bpo-26634: recursive_repr() now sets __qualname__ of wrapper.
    https://hg.python.org/cpython/rev/fb70ea8b7b2d

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants