Skip to content

Commit 9be6a11

Browse files
[3.12] gh-109818: reprlib.recursive_repr copies __type_params__ (… (#109999)
[3.12] gh-109818: `reprlib.recursive_repr` copies `__type_params__` (GH-109819). (cherry picked from commit f65f9e8) Co-authored-by: Nikita Sobolev <[email protected]>
1 parent dd67e59 commit 9be6a11

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Lib/reprlib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def wrapper(self):
2929
wrapper.__name__ = getattr(user_function, '__name__')
3030
wrapper.__qualname__ = getattr(user_function, '__qualname__')
3131
wrapper.__annotations__ = getattr(user_function, '__annotations__', {})
32+
wrapper.__type_params__ = getattr(user_function, '__type_params__', ())
3233
return wrapper
3334

3435
return decorating_function

Lib/test/test_reprlib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,5 +765,16 @@ def test_assigned_attributes(self):
765765
for name in assigned:
766766
self.assertIs(getattr(wrapper, name), getattr(wrapped, name))
767767

768+
def test__type_params__(self):
769+
class My:
770+
@recursive_repr()
771+
def __repr__[T: str](self, default: T = '') -> str:
772+
return default
773+
774+
type_params = My().__repr__.__type_params__
775+
self.assertEqual(len(type_params), 1)
776+
self.assertEqual(type_params[0].__name__, 'T')
777+
self.assertEqual(type_params[0].__bound__, str)
778+
768779
if __name__ == "__main__":
769780
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`reprlib.recursive_repr` not copying ``__type_params__`` from
2+
decorated function.

0 commit comments

Comments
 (0)