Message413898
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. |
|
Date |
User |
Action |
Args |
2022-02-24 09:47:13 | larry | set | recipients:
+ larry, rhettinger |
2022-02-24 09:47:13 | larry | set | messageid: <1645696033.77.0.27320800273.issue46847@roundup.psfhosted.org> |
2022-02-24 09:47:13 | larry | link | issue46847 messages |
2022-02-24 09:47:13 | larry | create | |
|