mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-61648: Detect line numbers of properties in doctests (GH-113161) (GH-113164)
(cherry picked from commit 8f8f0f97e1
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
6259dfa945
commit
ded4307fc1
4 changed files with 21 additions and 0 deletions
|
@ -1120,6 +1120,8 @@ class DocTestFinder:
|
||||||
|
|
||||||
# Find the line number for functions & methods.
|
# Find the line number for functions & methods.
|
||||||
if inspect.ismethod(obj): obj = obj.__func__
|
if inspect.ismethod(obj): obj = obj.__func__
|
||||||
|
if isinstance(obj, property):
|
||||||
|
obj = obj.fget
|
||||||
if inspect.isfunction(obj) and getattr(obj, '__doc__', None):
|
if inspect.isfunction(obj) and getattr(obj, '__doc__', None):
|
||||||
# We don't use `docstring` var here, because `obj` can be changed.
|
# We don't use `docstring` var here, because `obj` can be changed.
|
||||||
obj = obj.__code__
|
obj = obj.__code__
|
||||||
|
|
|
@ -49,5 +49,21 @@ class MethodWrapper:
|
||||||
'method_with_doctest'
|
'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
|
# https://github.com/python/cpython/issues/99433
|
||||||
str_wrapper = object().__str__
|
str_wrapper = object().__str__
|
||||||
|
|
|
@ -671,9 +671,11 @@ It used to be broken for quite some time until `bpo-28249`.
|
||||||
30 test.doctest_lineno.ClassWithDoctest
|
30 test.doctest_lineno.ClassWithDoctest
|
||||||
None test.doctest_lineno.ClassWithoutDocstring
|
None test.doctest_lineno.ClassWithoutDocstring
|
||||||
None test.doctest_lineno.MethodWrapper
|
None test.doctest_lineno.MethodWrapper
|
||||||
|
53 test.doctest_lineno.MethodWrapper.classmethod_with_doctest
|
||||||
39 test.doctest_lineno.MethodWrapper.method_with_docstring
|
39 test.doctest_lineno.MethodWrapper.method_with_docstring
|
||||||
45 test.doctest_lineno.MethodWrapper.method_with_doctest
|
45 test.doctest_lineno.MethodWrapper.method_with_doctest
|
||||||
None test.doctest_lineno.MethodWrapper.method_without_docstring
|
None test.doctest_lineno.MethodWrapper.method_without_docstring
|
||||||
|
61 test.doctest_lineno.MethodWrapper.property_with_doctest
|
||||||
4 test.doctest_lineno.func_with_docstring
|
4 test.doctest_lineno.func_with_docstring
|
||||||
12 test.doctest_lineno.func_with_doctest
|
12 test.doctest_lineno.func_with_doctest
|
||||||
None test.doctest_lineno.func_without_docstring
|
None test.doctest_lineno.func_without_docstring
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Detect line numbers of properties in doctests.
|
Loading…
Add table
Add a link
Reference in a new issue