[New-bugs-announce] [issue46847] functools.update_wrapper doesn't understand partial objects and annotations

Larry Hastings report at bugs.python.org
Thu Feb 24 04:47:13 EST 2022


New submission from Larry Hastings <larry at hastings.org>:

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.

----------
components: Library (Lib)
messages: 413898
nosy: larry, rhettinger
priority: normal
severity: normal
stage: test needed
status: open
title: functools.update_wrapper doesn't understand partial objects and annotations
type: behavior
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46847>
_______________________________________


More information about the New-bugs-announce mailing list