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

Skip to content

Commit 4845b97

Browse files
gh-107409: set __wrapped__ attribute in reprlib.recursive_repr (#107410)
Co-authored-by: Kumar Aditya <[email protected]>
1 parent 0f2fb6e commit 4845b97

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Lib/reprlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def wrapper(self):
2929
wrapper.__name__ = getattr(user_function, '__name__')
3030
wrapper.__qualname__ = getattr(user_function, '__qualname__')
3131
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
32+
wrapper.__wrapped__ = user_function
3233
return wrapper
3334

3435
return decorating_function

Lib/test/test_reprlib.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,5 +765,14 @@ def test_assigned_attributes(self):
765765
for name in assigned:
766766
self.assertIs(getattr(wrapper, name), getattr(wrapped, name))
767767

768+
def test__wrapped__(self):
769+
class X:
770+
def __repr__(self):
771+
return 'X()'
772+
f = __repr__ # save reference to check it later
773+
__repr__ = recursive_repr()(__repr__)
774+
775+
self.assertIs(X.f, X.__repr__.__wrapped__)
776+
768777
if __name__ == "__main__":
769778
unittest.main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set :attr:`!__wrapped__` attribute in :func:`reprlib.recursive_repr`.

0 commit comments

Comments
 (0)