From 91a8f8c16ca9a7e2466a8241d9b41769ef97d094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Thu, 8 Jul 2021 17:28:01 +0100 Subject: bpo-44446: support lineno being None in traceback.FrameSummary (GH-26781) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As of 088a15c49d99ecb4c3bef93f8f40dd513c6cae3b, lineno is None instead of -1 if there is no line number. Signed-off-by: Filipe LaĆ­ns --- Lib/test/test_traceback.py | 4 ++++ Lib/traceback.py | 2 ++ Misc/NEWS.d/next/Library/2021-06-17-22-39-34.bpo-44446.qwdRic.rst | 1 + 3 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2021-06-17-22-39-34.bpo-44446.qwdRic.rst diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 5681dfa..50ebcce 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -1204,6 +1204,10 @@ class TestFrame(unittest.TestCase): '"""Test cases for traceback module"""', f.line) + def test_no_line(self): + f = traceback.FrameSummary("f", None, "dummy") + self.assertEqual(f.line, None) + def test_explicit_line(self): f = traceback.FrameSummary("f", 1, "dummy", line="line") self.assertEqual("line", f.line) diff --git a/Lib/traceback.py b/Lib/traceback.py index cf1ba2a..7cb1241 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -310,6 +310,8 @@ class FrameSummary: @property def line(self): if self._line is None: + if self.lineno is None: + return None self._line = linecache.getline(self.filename, self.lineno) return self._line.strip() diff --git a/Misc/NEWS.d/next/Library/2021-06-17-22-39-34.bpo-44446.qwdRic.rst b/Misc/NEWS.d/next/Library/2021-06-17-22-39-34.bpo-44446.qwdRic.rst new file mode 100644 index 0000000..6d9758f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-06-17-22-39-34.bpo-44446.qwdRic.rst @@ -0,0 +1 @@ +Take into account that ``lineno`` might be ``None`` in :class:`traceback.FrameSummary`. -- cgit v0.12