Skip to content

Commit f65f9e8

Browse files
authored
gh-109818: reprlib.recursive_repr copies __type_params__ (#109819)
1 parent 5bb6f0f commit f65f9e8

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Lib/reprlib.py

+1
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
wrapper.__wrapped__ = user_function
3334
return wrapper
3435

Lib/test/test_reprlib.py

+11
Original file line numberDiff line numberDiff line change
@@ -774,5 +774,16 @@ def __repr__(self):
774774

775775
self.assertIs(X.f, X.__repr__.__wrapped__)
776776

777+
def test__type_params__(self):
778+
class My:
779+
@recursive_repr()
780+
def __repr__[T: str](self, default: T = '') -> str:
781+
return default
782+
783+
type_params = My().__repr__.__type_params__
784+
self.assertEqual(len(type_params), 1)
785+
self.assertEqual(type_params[0].__name__, 'T')
786+
self.assertEqual(type_params[0].__bound__, str)
787+
777788
if __name__ == "__main__":
778789
unittest.main()
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)