-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
gh-115392: Fix doctest reporting incorrect line numbers for decorated functions #115440
gh-115392: Fix doctest reporting incorrect line numbers for decorated functions #115440
Conversation
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.
LGTM. I'm not sure what would happen if you had a class decorator that used functools.wraps()
, but I can't think of a realistic reason why you might do that. So I don't think that's worth worrying about right now.
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.
Thank you!
Thanks @brianschubert for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Thanks @brianschubert for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…orated functions (pythonGH-115440) (cherry picked from commit bb791c7) Co-authored-by: Brian Schubert <[email protected]>
GH-115458 is a backport of this pull request to the 3.11 branch. |
…orated functions (pythonGH-115440) (cherry picked from commit bb791c7) Co-authored-by: Brian Schubert <[email protected]>
GH-115459 is a backport of this pull request to the 3.12 branch. |
This is known to fail on Python 3.11.9 because `--doctest-ufunc` was broken for wrapped ufuncs without docstrings by python/cpython#115440.
This broke doctest discovery for functions that are wrapped but do not define a |
Would you be able to open a new issue with a minimal repro? |
|
Fixes line numbers reported by
doctest
for wrapper functions (such as those returned byfunctools.wraps
).Currently,
doctest.DocTestFinder._find_lineno
looks at__code__.co_firstlineno
to determine the line number that a function's docstring starts at. This is incorrect for wrapper functions, where the location of the function definition is not the same as the location of the docstring being tested.Wrapper functions that have been updated with
functools.update_wrapper
have a__wrapped__
attribute that points to the underlying wrapped function. This PR adds a recursive check for__wrapped__
attributes on function objects to locate the original function that defined the docstring-under-test.