fix: set __wrapped__ on instrumented functions to preserve signature#556
Closed
gaoflow wants to merge 1 commit into
Closed
fix: set __wrapped__ on instrumented functions to preserve signature#556gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
The @TypeChecked decorator replaces the original function with an AST-instrumented copy but did not set __wrapped__ on the new function object. This prevented static analysis tools (e.g. PyCharm) from inspecting the original function signature, causing false 'unexpected argument' errors. Use functools.update_wrapper with updated=() to set __wrapped__ (and other wrapper bookkeeping like __dict__) without overwriting the manually-copied attributes. Fixes: agronholm#553 Signed-off-by: Vincent Gao <gaobing1230@gmail.com>
Owner
|
More AI slop. Banned. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
@typecheckeddecorator replaces the original function with anAST-instrumented copy but did not set
__wrapped__on the newfunction object. This prevented static analysis tools (e.g. PyCharm,
mypy) from inspecting the original function signature, causing false
"unexpected argument" errors.
Fix: use
functools.update_wrapper(new_function, f, updated=())ininstrument()to set__wrapped__and copy__dict__withoutoverwriting the already-manually-copied attributes.
Fixes: #553