[Python-checkins] gh-107409: set `__wrapped__` attribute in `reprlib.recursive_repr` (#107410)
kumaraditya303
webhook-mailer at python.org
Thu Aug 10 02:55:53 EDT 2023
https://github.com/python/cpython/commit/4845b9712f2c187743344eca43fa1fb896bddfd6
commit: 4845b9712f2c187743344eca43fa1fb896bddfd6
branch: main
author: denballakh <47365157+denballakh at users.noreply.github.com>
committer: kumaraditya303 <kumaraditya at python.org>
date: 2023年08月10日T06:55:49Z
summary:
gh-107409: set `__wrapped__` attribute in `reprlib.recursive_repr` (#107410)
Co-authored-by: Kumar Aditya <kumaraditya at python.org>
files:
A Misc/NEWS.d/next/Library/2023-07-29-02-36-50.gh-issue-107409.HG27Nu.rst
M Lib/reprlib.py
M Lib/test/test_reprlib.py
diff --git a/Lib/reprlib.py b/Lib/reprlib.py
index a92b3e3dbb613..840dd0e20132b 100644
--- a/Lib/reprlib.py
+++ b/Lib/reprlib.py
@@ -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
diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py
index e7216d427200c..502287b620d06 100644
--- a/Lib/test/test_reprlib.py
+++ b/Lib/test/test_reprlib.py
@@ -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()
diff --git a/Misc/NEWS.d/next/Library/2023-07-29-02-36-50.gh-issue-107409.HG27Nu.rst b/Misc/NEWS.d/next/Library/2023-07-29-02-36-50.gh-issue-107409.HG27Nu.rst
new file mode 100644
index 0000000000000..1ecc7207605c7
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-07-29-02-36-50.gh-issue-107409.HG27Nu.rst
@@ -0,0 +1 @@
+Set :attr:`!__wrapped__` attribute in :func:`reprlib.recursive_repr`.
More information about the Python-checkins
mailing list