Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8f8f0f9

Browse files
pythongh-61648: Detect line numbers of properties in doctests (pythonGH-113161)
1 parent737d23f commit8f8f0f9

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

‎Lib/doctest.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,8 @@ def _find_lineno(self, obj, source_lines):
11361136

11371137
# Find the line number for functions & methods.
11381138
ifinspect.ismethod(obj):obj=obj.__func__
1139+
ifisinstance(obj,property):
1140+
obj=obj.fget
11391141
ifinspect.isfunction(obj)andgetattr(obj,'__doc__',None):
11401142
# We don't use `docstring` var here, because `obj` can be changed.
11411143
obj=obj.__code__

‎Lib/test/doctest_lineno.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,21 @@ def method_with_doctest(self):
4949
'method_with_doctest'
5050
"""
5151

52+
@classmethod
53+
defclassmethod_with_doctest(cls):
54+
"""
55+
This has a doctest!
56+
>>> MethodWrapper.classmethod_with_doctest.__name__
57+
'classmethod_with_doctest'
58+
"""
59+
60+
@property
61+
defproperty_with_doctest(self):
62+
"""
63+
This has a doctest!
64+
>>> MethodWrapper.property_with_doctest.__name__
65+
'property_with_doctest'
66+
"""
67+
5268
# https://github.com/python/cpython/issues/99433
5369
str_wrapper=object().__str__

‎Lib/test/test_doctest.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,11 @@ def basics(): r"""
670670
30 test.doctest_lineno.ClassWithDoctest
671671
None test.doctest_lineno.ClassWithoutDocstring
672672
None test.doctest_lineno.MethodWrapper
673+
53 test.doctest_lineno.MethodWrapper.classmethod_with_doctest
673674
39 test.doctest_lineno.MethodWrapper.method_with_docstring
674675
45 test.doctest_lineno.MethodWrapper.method_with_doctest
675676
None test.doctest_lineno.MethodWrapper.method_without_docstring
677+
61 test.doctest_lineno.MethodWrapper.property_with_doctest
676678
4 test.doctest_lineno.func_with_docstring
677679
12 test.doctest_lineno.func_with_doctest
678680
None test.doctest_lineno.func_without_docstring
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Detect line numbers of properties in doctests.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp