Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3b366d

Browse files
Issue #26634: recursive_repr() now sets __qualname__ of wrapper.
Patch by Xiang Zhang.
1 parent a7c0ff2 commit b3b366d

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lib/reprlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def wrapper(self):
3030
wrapper.__module__ = getattr(user_function, '__module__')
3131
wrapper.__doc__ = getattr(user_function, '__doc__')
3232
wrapper.__name__ = getattr(user_function, '__name__')
33+
wrapper.__qualname__ = getattr(user_function, '__qualname__')
3334
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
3435
return wrapper
3536

Lib/test/test_reprlib.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,13 @@ class MyContainer2(MyContainer):
374374
def __repr__(self):
375375
return '<' + ', '.join(map(str, self.values)) + '>'
376376

377+
class MyContainer3:
378+
def __repr__(self):
379+
'Test document content'
380+
pass
381+
wrapped = __repr__
382+
wrapper = recursive_repr()(wrapped)
383+
377384
class TestRecursiveRepr(unittest.TestCase):
378385
def test_recursive_repr(self):
379386
m = MyContainer(list('abcde'))
@@ -387,5 +394,12 @@ def test_recursive_repr(self):
387394
m.append(m)
388395
self.assertEqual(repr(m), '<a, b, c, d, e, +++, x, +++>')
389396

397+
def test_assigned_attributes(self):
398+
from functools import WRAPPER_ASSIGNMENTS as assigned
399+
wrapped = MyContainer3.wrapped
400+
wrapper = MyContainer3.wrapper
401+
for name in assigned:
402+
self.assertIs(getattr(wrapper, name), getattr(wrapped, name))
403+
390404
if __name__ == "__main__":
391405
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ Core and Builtins
107107
Library
108108
-------
109109

110+
- Issue #26634: recursive_repr() now sets __qualname__ of wrapper. Patch by
111+
Xiang Zhang.
112+
110113
- Issue #26804: urllib.request will prefer lower_case proxy environment
111114
variables over UPPER_CASE or Mixed_Case ones. Patch contributed by Hans-Peter
112115
Jansen.

0 commit comments

Comments
 (0)