Skip to content

Commit

Permalink
[3.12] gh-109818: reprlib.recursive_repr copies __type_params__ (… (
Browse files Browse the repository at this point in the history
#109999)

[3.12] gh-109818: `reprlib.recursive_repr` copies `__type_params__` (GH-109819).
(cherry picked from commit f65f9e8)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
  • Loading branch information
JelleZijlstra and sobolevn authored Oct 2, 2023
1 parent dd67e59 commit 9be6a11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions Lib/reprlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__', ())
return wrapper

return decorating_function
Expand Down
11 changes: 11 additions & 0 deletions Lib/test/test_reprlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,5 +765,16 @@ def test_assigned_attributes(self):
for name in assigned:
self.assertIs(getattr(wrapper, name), getattr(wrapped, name))

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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`reprlib.recursive_repr` not copying ``__type_params__`` from
decorated function.

0 comments on commit 9be6a11

Please sign in to comment.