[3.12] gh-115392: Fix doctest reporting incorrect line numbers for de… · python/cpython@13af281 · GitHub
Skip to content

Commit 13af281

Browse files
[3.12] gh-115392: Fix doctest reporting incorrect line numbers for decorated 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>
1 parent 5931716 commit 13af281

5 files changed

Lines changed: 23 additions & 1 deletion

File tree

Lib/doctest.py

Lines changed: 1 addition & 1 deletion
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This module is used in `doctest_lineno.py`.
2+
import functools
3+
4+
5+
def decorator(f):
6+
@functools.wraps(f)
7+
def inner():
8+
return f()
9+
10+
return inner

Lib/test/test_doctest/doctest_lineno.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,12 @@ def property_with_doctest(self):
6767

6868
# https://github.com/python/cpython/issues/99433
6969
str_wrapper = object().__str__
70+
71+
72+
# https://github.com/python/cpython/issues/115392
73+
from test.test_doctest.decorator_mod import decorator
74+
75+
@decorator
76+
@decorator
77+
def func_with_docstring_wrapped():
78+
"""Some unrelated info."""

Lib/test/test_doctest/test_doctest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ def basics(): r"""
686686
None test.test_doctest.doctest_lineno.MethodWrapper.method_without_docstring
687687
61 test.test_doctest.doctest_lineno.MethodWrapper.property_with_doctest
688688
4 test.test_doctest.doctest_lineno.func_with_docstring
689+
77 test.test_doctest.doctest_lineno.func_with_docstring_wrapped
689690
12 test.test_doctest.doctest_lineno.func_with_doctest
690691
None test.test_doctest.doctest_lineno.func_without_docstring
691692
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)