Content-Length: 291446 | pFad | http://github.com/aisk/cpython/commit/40384e42a37ce641592ad44da11b9d1de2db4a81

86 gh-61648: Detect line numbers of properties in doctests (GH-113161) · aisk/cpython@40384e4 · GitHub
Skip to content

Commit

Permalink
pythongh-61648: Detect line numbers of properties in doctests (python…
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored and aisk committed Feb 11, 2024
1 parent e74152f commit 40384e4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,8 @@ def _find_lineno(self, obj, source_lines):

# Find the line number for functions & methods.
if inspect.ismethod(obj): obj = obj.__func__
if isinstance(obj, property):
obj = obj.fget
if inspect.isfunction(obj) and getattr(obj, '__doc__', None):
# We don't use `docstring` var here, because `obj` can be changed.
obj = obj.__code__
Expand Down
16 changes: 16 additions & 0 deletions Lib/test/doctest_lineno.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,21 @@ def method_with_doctest(self):
'method_with_doctest'
"""

@classmethod
def classmethod_with_doctest(cls):
"""
This has a doctest!
>>> MethodWrapper.classmethod_with_doctest.__name__
'classmethod_with_doctest'
"""

@property
def property_with_doctest(self):
"""
This has a doctest!
>>> MethodWrapper.property_with_doctest.__name__
'property_with_doctest'
"""

# https://github.com/python/cpython/issues/99433
str_wrapper = object().__str__
2 changes: 2 additions & 0 deletions Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,11 @@ def basics(): r"""
30 test.doctest_lineno.ClassWithDoctest
None test.doctest_lineno.ClassWithoutDocstring
None test.doctest_lineno.MethodWrapper
53 test.doctest_lineno.MethodWrapper.classmethod_with_doctest
39 test.doctest_lineno.MethodWrapper.method_with_docstring
45 test.doctest_lineno.MethodWrapper.method_with_doctest
None test.doctest_lineno.MethodWrapper.method_without_docstring
61 test.doctest_lineno.MethodWrapper.property_with_doctest
4 test.doctest_lineno.func_with_docstring
12 test.doctest_lineno.func_with_doctest
None test.doctest_lineno.func_without_docstring
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Detect line numbers of properties in doctests.

0 comments on commit 40384e4

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/aisk/cpython/commit/40384e42a37ce641592ad44da11b9d1de2db4a81

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy