Skip to content

Commit

Permalink
update_wrapper() updates __annotate__, not __annotations__
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jun 1, 2024
1 parent c11cc6d commit 672511a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# wrapper functions that can handle naive introspection

WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__qualname__', '__doc__',
'__annotations__', '__type_params__')
'__annotate__', '__type_params__')
WRAPPER_UPDATES = ('__dict__',)
def update_wrapper(wrapper,
wrapped,
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,24 @@ def wrapper(*args): pass
self.assertEqual(wrapper.__annotations__, {})
self.assertEqual(wrapper.__type_params__, ())

def test_update_wrapper_annotations(self):
def inner(x: int): pass
def wrapper(*args): pass

functools.update_wrapper(wrapper, inner)
self.assertEqual(wrapper.__annotations__, {'x': int})
self.assertIs(wrapper.__annotate__, inner.__annotate__)

def with_forward_ref(x: undefined): pass
def wrapper(*args): pass

functools.update_wrapper(wrapper, with_forward_ref)

self.assertIs(wrapper.__annotate__, with_forward_ref.__annotate__)

undefined = str
self.assertEqual(wrapper.__annotations__, {'x': undefined})


class TestWraps(TestUpdateWrapper):

Expand Down

0 comments on commit 672511a

Please sign in to comment.