summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordenballakh <47365157+denballakh@users.noreply.github.com>2023-08-10 06:55:49 (GMT)
committerGitHub <noreply@github.com>2023-08-10 06:55:49 (GMT)
commit4845b9712f2c187743344eca43fa1fb896bddfd6 (patch)
tree326bdc801301ba9eff61d333d10b26ba5e97cdbc
parent0f2fb6efb4d5d8ca43a0e779b89a8e805880e09a (diff)
downloadcpython-4845b9712f2c187743344eca43fa1fb896bddfd6.zip
cpython-4845b9712f2c187743344eca43fa1fb896bddfd6.tar.gz
cpython-4845b9712f2c187743344eca43fa1fb896bddfd6.tar.bz2
gh-107409: set `__wrapped__` attribute in `reprlib.recursive_repr` (#107410)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
-rw-r--r--Lib/reprlib.py1
-rw-r--r--Lib/test/test_reprlib.py9
-rw-r--r--Misc/NEWS.d/next/Library/2023-07-29-02-36-50.gh-issue-107409.HG27Nu.rst1
3 files changed, 11 insertions, 0 deletions
diff --git a/Lib/reprlib.py b/Lib/reprlib.py
index a92b3e3..840dd0e 100644
--- a/Lib/reprlib.py
+++ b/Lib/reprlib.py
@@ -29,6 +29,7 @@ def recursive_repr(fillvalue='...'):
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 e7216d4..502287b 100644
--- a/Lib/test/test_reprlib.py
+++ b/Lib/test/test_reprlib.py
@@ -765,5 +765,14 @@ class TestRecursiveRepr(unittest.TestCase):
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 0000000..1ecc720
--- /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`.