Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf65f9e8

Browse files
authored
gh-109818:reprlib.recursive_repr copies__type_params__ (#109819)
1 parent5bb6f0f commitf65f9e8

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
wrapper.__wrapped__=user_function
3334
returnwrapper
3435

‎Lib/test/test_reprlib.py‎

Lines changed: 11 additions & 0 deletions
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+
deftest__type_params__(self):
778+
classMy:
779+
@recursive_repr()
780+
def__repr__[T:str](self,default:T='')->str:
781+
returndefault
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()
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)

[8]ページ先頭

©2009-2025 Movatter.jp