[Python-checkins] [3.10] bpo-44446: support lineno being None in traceback.FrameSummary (GH-26781) (GH-27072)

pablogsal webhook-mailer at python.org
Thu Jul 8 12:47:22 EDT 2021


https://github.com/python/cpython/commit/61eb9b5dfd919ba5d1ec9f7df0137f2e6d196972
commit: 61eb9b5dfd919ba5d1ec9f7df0137f2e6d196972
branch: 3.10
author: Pablo Galindo <Pablogsal at gmail.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-07-08T17:47:12+01:00
summary:

[3.10] bpo-44446: support lineno being None in traceback.FrameSummary (GH-26781) (GH-27072)

As of 088a15c49d99ecb4c3bef93f8f40dd513c6cae3b, lineno is None instead
of -1 if there is no line number.

Signed-off-by: Filipe Laíns <lains at riseup.net>.
(cherry picked from commit 91a8f8c16ca9a7e2466a8241d9b41769ef97d094)

Co-authored-by: Filipe Laíns <lains at riseup.net>

Co-authored-by: Filipe Laíns <lains at riseup.net>

files:
A Misc/NEWS.d/next/Library/2021-06-17-22-39-34.bpo-44446.qwdRic.rst
M Lib/test/test_traceback.py
M Lib/traceback.py

diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index dd9459040ebc3..61d86a1166e71 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -1001,6 +1001,10 @@ def test_lazy_lines(self):
             '"""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 7a7cca1b67702..463cb221fa2c8 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -301,9 +301,10 @@ def __len__(self):
     @property
     def line(self):
         if self._line is None:
-            self._line = linecache.getline(self.filename, self.lineno).strip()
-        return self._line
-
+            if self.lineno is None:
+                return None
+            self._line = linecache.getline(self.filename, self.lineno)
+        return self._line.strip()
 
 def walk_stack(f):
     """Walk a stack yielding the frame and line number for each frame.
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 0000000000000..6d9758f42dd04
--- /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`.



More information about the Python-checkins mailing list