summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFilipe Laíns <lains@riseup.net>2021-07-08 16:28:01 (GMT)
committerGitHub <noreply@github.com>2021-07-08 16:28:01 (GMT)
commit91a8f8c16ca9a7e2466a8241d9b41769ef97d094 (patch)
tree6ba42ea9ec9549291af04943f8c4521e613dfdfe /Lib
parentbbf2fb6c7ae78f40483606f467739a58cd747270 (diff)
downloadcpython-91a8f8c16ca9a7e2466a8241d9b41769ef97d094.zip
cpython-91a8f8c16ca9a7e2466a8241d9b41769ef97d094.tar.gz
cpython-91a8f8c16ca9a7e2466a8241d9b41769ef97d094.tar.bz2
bpo-44446: support lineno being None in traceback.FrameSummary (GH-26781)
As of 088a15c49d99ecb4c3bef93f8f40dd513c6cae3b, lineno is None instead of -1 if there is no line number. Signed-off-by: Filipe Laíns <lains@riseup.net>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_traceback.py4
-rw-r--r--Lib/traceback.py2
2 files changed, 6 insertions, 0 deletions
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()