Skip to content

Commit 0fc58c1

Browse files
bpo-46306: simplify CodeType attribute access in doctest.py (GH-30481)
Assume co_firstlineno always exists on types.CodeType objects. Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
1 parent 8d59d25 commit 0fc58c1

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Lib/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ def _find_lineno(self, obj, source_lines):
11131113
if inspect.istraceback(obj): obj = obj.tb_frame
11141114
if inspect.isframe(obj): obj = obj.f_code
11151115
if inspect.iscode(obj):
1116-
lineno = getattr(obj, 'co_firstlineno', None)-1
1116+
lineno = obj.co_firstlineno - 1
11171117

11181118
# Find the line number where the docstring starts. Assume
11191119
# that it's the first line that begins with a quote mark.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Assume that :class:`types.CodeType` always has :attr:`types.CodeType.co_firstlineno` in
2+
:mod:`doctest`.

0 commit comments

Comments
 (0)