FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-115392: Fix doctest reporting incorrect line numbers for decorated functions by brianschubert · Pull Request #115440 · python/cpython · GitHub

/ cpython Public

gh-115392: Fix doctest reporting incorrect line numbers for decorated functions - #115440

Merged
AlexWaygood merged 3 commits into
python:mainfrom
brianschubert:fix-doctest-wrapper-lineno
Feb 14, 2024
Merged

gh-115392: Fix doctest reporting incorrect line numbers for decorated functions#115440
AlexWaygood merged 3 commits into
python:mainfrom
brianschubert:fix-doctest-wrapper-lineno

Conversation

brianschubert commented Feb 14, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Fixes line numbers reported by doctest for wrapper functions (such as those returned by functools.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.

Comment thread Lib/doctest.py Outdated

AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thank you!

AlexWaygood merged commit bb791c7 into python:main Feb 14, 2024
AlexWaygood added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Feb 14, 2024

Copy link
Copy Markdown

Thanks @brianschubert for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

Copy link
Copy Markdown

Thanks @brianschubert for the PR, and @AlexWaygood for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 14, 2024
…orated functions (pythonGH-115440)

(cherry picked from commit bb791c7)

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>

bedevere-app Bot commented Feb 14, 2024

Copy link
Copy Markdown

GH-115458 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 14, 2024
…orated functions (pythonGH-115440)

(cherry picked from commit bb791c7)

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
bedevere-app Bot removed the needs backport to 3.11 only security fixes label Feb 14, 2024

bedevere-app Bot commented Feb 14, 2024

Copy link
Copy Markdown

GH-115459 is a backport of this pull request to the 3.12 branch.

bedevere-app Bot removed the needs backport to 3.12 only security fixes label Feb 14, 2024
AlexWaygood pushed a commit that referenced this pull request Feb 14, 2024
…corated functions (GH-115440) (#115458)

gh-115392: Fix doctest reporting incorrect line numbers for decorated functions (GH-115440)
(cherry picked from commit bb791c7)

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
AlexWaygood pushed a commit that referenced this pull request Feb 14, 2024
…corated functions (GH-115440) (#115459)

gh-115392: Fix doctest reporting incorrect line numbers for decorated functions (GH-115440)
(cherry picked from commit bb791c7)

Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
lpsinger added a commit to lpsinger/pytest-doctestplus that referenced this pull request Apr 9, 2024
This is known to fail on Python 3.11.9 because `--doctest-ufunc`
was broken for wrapped ufuncs without docstrings by
python/cpython#115440.

lpsinger commented Apr 9, 2024
edited
Loading

Copy link
Copy Markdown

This broke doctest discovery for functions that are wrapped but do not define a __doc__. See scientific-python/pytest-doctestplus#248.

Copy link
Copy Markdown
Member

This broke doctest discovery for functions that are wrapped but do not define a __doc__. See scientific-python/pytest-doctestplus#248.

Would you be able to open a new issue with a minimal repro?

lpsinger commented Apr 9, 2024

Copy link
Copy Markdown

This broke doctest discovery for functions that are wrapped but do not define a __doc__. See scientific-python/pytest-doctestplus#248.

Would you be able to open a new issue with a minimal repro?

#117692

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL