Skip to content

Commit

Permalink
gh-107409: set __wrapped__ attribute in reprlib.recursive_repr (#…
Browse files Browse the repository at this point in the history
…107410)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
  • Loading branch information
denballakh and kumaraditya303 authored Aug 10, 2023
1 parent 0f2fb6e commit 4845b97
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions Lib/reprlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def wrapper(self):
wrapper.__name__ = getattr(user_function, '__name__')
wrapper.__qualname__ = getattr(user_function, '__qualname__')
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
wrapper.__wrapped__ = user_function
return wrapper

return decorating_function
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_reprlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,5 +765,14 @@ def test_assigned_attributes(self):
for name in assigned:
self.assertIs(getattr(wrapper, name), getattr(wrapped, name))

def test__wrapped__(self):
class X:
def __repr__(self):
return 'X()'
f = __repr__ # save reference to check it later
__repr__ = recursive_repr()(__repr__)

self.assertIs(X.f, X.__repr__.__wrapped__)

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set :attr:`!__wrapped__` attribute in :func:`reprlib.recursive_repr`.

0 comments on commit 4845b97

Please sign in to comment.