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>
This commit is contained in:
Nikita Sobolev 2022-01-08 23:13:42 +03:00 committed by GitHub
parent 8d59d2563b
commit 0fc58c1e05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -1113,7 +1113,7 @@ def _find_lineno(self, obj, source_lines):
if inspect.istraceback(obj): obj = obj.tb_frame
if inspect.isframe(obj): obj = obj.f_code
if inspect.iscode(obj):
lineno = getattr(obj, 'co_firstlineno', None)-1
lineno = obj.co_firstlineno - 1
# Find the line number where the docstring starts. Assume
# that it's the first line that begins with a quote mark.

View file

@ -0,0 +1,2 @@
Assume that :class:`types.CodeType` always has :attr:`types.CodeType.co_firstlineno` in
:mod:`doctest`.