Skip to content

Commit

Permalink
bpo-44446: support lineno being None in traceback.FrameSummary (GH-26781
Browse files Browse the repository at this point in the history
)

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

Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
FFY00 committed Jul 8, 2021
1 parent bbf2fb6 commit 91a8f8c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Lib/test/test_traceback.py
Expand Up @@ -1204,6 +1204,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)
Expand Down
2 changes: 2 additions & 0 deletions Lib/traceback.py
Expand Up @@ -310,6 +310,8 @@ def _original_line(self):
@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()

Expand Down
@@ -0,0 +1 @@
Take into account that ``lineno`` might be ``None`` in :class:`traceback.FrameSummary`.

0 comments on commit 91a8f8c

Please sign in to comment.