]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-107409: set `__wrapped__` attribute in `reprlib.recursive_repr` (#107410)
authordenballakh <47365157+denballakh@users.noreply.github.com>
Thu, 10 Aug 2023 06:55:49 +0000 (11:55 +0500)
committerGitHub <noreply@github.com>
Thu, 10 Aug 2023 06:55:49 +0000 (06:55 +0000)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Lib/reprlib.py
Lib/test/test_reprlib.py
Misc/NEWS.d/next/Library/2023-07-29-02-36-50.gh-issue-107409.HG27Nu.rst [new file with mode: 0644]

index a92b3e3dbb613a6b9baee8a8a7d0b6e3ecac3e96..840dd0e20132b120a87f452e2108c447f018a3d7 100644 (file)
@@ -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
index e7216d427200c1500e5b3a2af19bf1c21b73c4dd..502287b620d0662bc7d047f5dc20ffa20083c8b0 100644 (file)
@@ -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 (file)
index 0000000..1ecc720
--- /dev/null
@@ -0,0 +1 @@
+Set :attr:`!__wrapped__` attribute in :func:`reprlib.recursive_repr`.