This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: recursive_repr forgets to override __qualname__ of wrapper
Type: behavior Stage: commit review
Components: Library (Lib) Versions: Python 3.6, Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, rhettinger, serhiy.storchaka, xiang.zhang
Priority: normal Keywords: patch

Created on 2016-03-24 04:09 by xiang.zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
qualname_of_recursive_repr_in_reprlib.patch xiang.zhang, 2016-03-24 04:09 review
qualname_of_recursive_repr_in_reprlib_v2.patch xiang.zhang, 2016-03-24 06:21 review
Messages (5)
msg262326 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-03-24 04:09
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.
msg262327 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-03-24 05:02
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.
msg262329 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-03-24 06:21
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.
msg264048 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-04-23 06:30
LGTM. I would commit the patch to 3.5 too.
msg264218 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-04-26 06:31
New changeset 1f0369547b0e by Serhiy Storchaka in branch '3.5':
Issue #26634: recursive_repr() now sets __qualname__ of wrapper.

New changeset fb70ea8b7b2d by Serhiy Storchaka in branch 'default':
Issue #26634: recursive_repr() now sets __qualname__ of wrapper.
Date User Action Args
2022-04-11 14:58:28adminsetgithub: 70821
2016-04-26 06:32:05serhiy.storchakasetstatus: open -> closed
resolution: fixed
2016-04-26 06:31:37python-devsetnosy: + python-dev
messages: + msg264218
2016-04-26 06:12:53rhettingersetassignee: rhettinger -> serhiy.storchaka
2016-04-23 06:30:14serhiy.storchakasetversions: + Python 3.5
nosy: + serhiy.storchaka

messages: + msg264048

stage: commit review
2016-03-24 06:21:11xiang.zhangsetfiles: + qualname_of_recursive_repr_in_reprlib_v2.patch

messages: + msg262329
2016-03-24 05:02:06rhettingersetassignee: rhettinger

messages: + msg262327
nosy: + rhettinger
2016-03-24 04:09:36xiang.zhangcreate