From cc26fa4c6efafb2b007fa67b77c6e092f7538eb7 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 25 Sep 2023 10:00:25 +0300 Subject: [PATCH 1/2] gh-109818: `repllib.recursive_repr` copies `__type_params__` --- Lib/reprlib.py | 1 + Lib/test/test_reprlib.py | 11 +++++++++++ .../2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst diff --git a/Lib/reprlib.py b/Lib/reprlib.py index 840dd0e20132b1..05bb1a0eb01795 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.__type_params__ = getattr(user_function, '__type_params__', ()) wrapper.__wrapped__ = user_function return wrapper diff --git a/Lib/test/test_reprlib.py b/Lib/test/test_reprlib.py index 502287b620d066..3e93b561c143d8 100644 --- a/Lib/test/test_reprlib.py +++ b/Lib/test/test_reprlib.py @@ -774,5 +774,16 @@ def __repr__(self): self.assertIs(X.f, X.__repr__.__wrapped__) + def test__type_params__(self): + class My: + @recursive_repr() + def __repr__[T: str](self, default: T = '') -> str: + return default + + type_params = My().__repr__.__type_params__ + self.assertEqual(len(type_params), 1) + self.assertEqual(type_params[0].__name__, 'T') + self.assertEqual(type_params[0].__bound__, str) + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst b/Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst new file mode 100644 index 00000000000000..65df68f154df49 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst @@ -0,0 +1,2 @@ +Fix :func:`repllib.recursive_repl` not copying ``__type_params__`` from +decorated function. From fe9dbfa014752dbcbb155a5ef6930598d7509764 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 25 Sep 2023 10:18:53 +0300 Subject: [PATCH 2/2] Update Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst Co-authored-by: Alex Waygood --- .../next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst b/Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst index 65df68f154df49..184086af2585ea 100644 --- a/Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst +++ b/Misc/NEWS.d/next/Library/2023-09-25-09-59-59.gh-issue-109818.dLRtT-.rst @@ -1,2 +1,2 @@ -Fix :func:`repllib.recursive_repl` not copying ``__type_params__`` from +Fix :func:`reprlib.recursive_repr` not copying ``__type_params__`` from decorated function.