diff --git a/Lib/doctest.py b/Lib/doctest.py index b27cbdfed46..4735b598526 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 00000000000..02943c95a7d --- /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`.