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

Commit9be6a11

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 commitf65f9e8)Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
1 parentdd67e59 commit9be6a11

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
returnwrapper
3334

3435
returndecorating_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
fornameinassigned:
766766
self.assertIs(getattr(wrapper,name),getattr(wrapped,name))
767767

768+
deftest__type_params__(self):
769+
classMy:
770+
@recursive_repr()
771+
def__repr__[T:str](self,default:T='')->str:
772+
returndefault
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)

[8]ページ先頭

©2009-2025 Movatter.jp