diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-01-08 20:13:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-08 20:13:42 (GMT) |
commit | 0fc58c1e051026baff4919d8519ce2aabe3b2ba1 (patch) | |
tree | 10d055c358b5d6d3dd2f6a4912020378b72658bf | |
parent | 8d59d2563b914b7208779834895c080c70cd94dd (diff) | |
download | cpython-0fc58c1e051026baff4919d8519ce2aabe3b2ba1.zip cpython-0fc58c1e051026baff4919d8519ce2aabe3b2ba1.tar.gz cpython-0fc58c1e051026baff4919d8519ce2aabe3b2ba1.tar.bz2 |
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>
-rw-r--r-- | Lib/doctest.py | 2 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2022-01-08-13-53-25.bpo-46306.1_es8z.rst | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index b27cbdf..4735b59 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -1113,7 +1113,7 @@ class DocTestFinder: 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. diff --git a/Misc/NEWS.d/next/Library/2022-01-08-13-53-25.bpo-46306.1_es8z.rst b/Misc/NEWS.d/next/Library/2022-01-08-13-53-25.bpo-46306.1_es8z.rst new file mode 100644 index 0000000..02943c9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-01-08-13-53-25.bpo-46306.1_es8z.rst @@ -0,0 +1,2 @@ +Assume that :class:`types.CodeType` always has :attr:`types.CodeType.co_firstlineno` in +:mod:`doctest`. |