-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix inconsistent function inspection for @decorated functions #2246
Conversation
Signed-off-by: rashidakanchwala <rashida_kanchwala@mckinsey.com>
Signed-off-by: rashidakanchwala <rashida_kanchwala@mckinsey.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Rashida, LGTM.
nit: maybe we should add a test for non-wraps Decorators too?
both tests are there, there's one for non-wraps which was already there. i added one for wrap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well !! should we add to release note ?
Thank you @rashidakanchwala
Signed-off-by: rashidakanchwala <rashida_kanchwala@mckinsey.com>
Description
Resolves #2240
When a function is decorated, the decorator often wraps the original function with additional logic. Some decorators, such as
@pandera.check_output
, usefunctools.wraps
, which preserves the original function’s metadata. This allows inspection tools likeinspect.getsource
to return the code of the original function instead of the wrapper.However, decorators that do not use
functools.wraps
replace the original function entirely with the wrapper. As a result, inspection tools will return the decorator code instead of the original function's code, which can cause confusion.This PR addresses this inconsistency by:
__wrapped__
attribute (set byfunctools.wraps
) and returning the original function if it exists.__wrapped__
falling back to inspecting the closure to retrieve the original function, if available.QA notes
demo_project
, replace feature_engineering/nodes.py with the below files which consists of both user created decorator and pandera decorator. Runkedro viz
with the old code and you will see how one @pandera.decorator displays decorator when you doShow Code
and the user created decorator displays the original code.Click to expand the the nodes.py file
Checklist
RELEASE.md
file