Skip to content

Commit 672511a

Browse files
committed
update_wrapper() updates __annotate__, not __annotations__
1 parent c11cc6d commit 672511a

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lib/functools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# wrapper functions that can handle naive introspection
3232

3333
WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__qualname__', '__doc__',
34-
'__annotations__', '__type_params__')
34+
'__annotate__', '__type_params__')
3535
WRAPPER_UPDATES = ('__dict__',)
3636
def update_wrapper(wrapper,
3737
wrapped,

Lib/test/test_functools.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,24 @@ def wrapper(*args): pass
718718
self.assertEqual(wrapper.__annotations__, {})
719719
self.assertEqual(wrapper.__type_params__, ())
720720

721+
def test_update_wrapper_annotations(self):
722+
def inner(x: int): pass
723+
def wrapper(*args): pass
724+
725+
functools.update_wrapper(wrapper, inner)
726+
self.assertEqual(wrapper.__annotations__, {'x': int})
727+
self.assertIs(wrapper.__annotate__, inner.__annotate__)
728+
729+
def with_forward_ref(x: undefined): pass
730+
def wrapper(*args): pass
731+
732+
functools.update_wrapper(wrapper, with_forward_ref)
733+
734+
self.assertIs(wrapper.__annotate__, with_forward_ref.__annotate__)
735+
736+
undefined = str
737+
self.assertEqual(wrapper.__annotations__, {'x': undefined})
738+
721739

722740
class TestWraps(TestUpdateWrapper):
723741

0 commit comments

Comments
 (0)