This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: functools.update_wrapper doesn't understand partial objects and annotations
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AlexWaygood, JelleZijlstra, eric.araujo, larry, rhettinger, sobolevn
Priority: normal Keywords:

Created on 2022-02-24 09:47 by larry, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg413898 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2022-02-24 09:47
functools.update_wrapper currently copies over every attribute listed in the "assigned" parameter, which defaults to WRAPPER_ASSIGNMENTS, which means it copies the wrapped function's __annotations__ to the wrapper.  This is slightly wrong if the wrapper occludes an annotated parameter:

    def foo(a: int, b: str, c: float):
        print(a, b, c)

    import functools

    foo_a = functools.partial(foo, 3)
    functools.update_wrapper(foo_a, foo)

    print(foo_a.__annotations__)

In this case, foo_a.__annotations__ contains an annotation for a parameter named "a", even though foo_a doesn't have a parameter named "a".

This problem occurred to me just after I filed #46846; the two issues are definitely related.
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 91003
2022-02-26 15:06:27eric.araujosetnosy: + eric.araujo
2022-02-24 10:15:08AlexWaygoodsetnosy: + JelleZijlstra, sobolevn, AlexWaygood
2022-02-24 09:47:13larrycreate