Skip to content

Commit 61eb9b5

Browse files
pablogsalFFY00
andauthored
[3.10] bpo-44446: support lineno being None in traceback.FrameSummary (GH-26781) (GH-27072)
As of 088a15c, lineno is None instead of -1 if there is no line number. Signed-off-by: Filipe Laíns <lains@riseup.net>. (cherry picked from commit 91a8f8c) Co-authored-by: Filipe Laíns <lains@riseup.net> Co-authored-by: Filipe Laíns <lains@riseup.net>
1 parent 08697ac commit 61eb9b5

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Lib/test/test_traceback.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,10 @@ def test_lazy_lines(self):
10011001
'"""Test cases for traceback module"""',
10021002
f.line)
10031003

1004+
def test_no_line(self):
1005+
f = traceback.FrameSummary("f", None, "dummy")
1006+
self.assertEqual(f.line, None)
1007+
10041008
def test_explicit_line(self):
10051009
f = traceback.FrameSummary("f", 1, "dummy", line="line")
10061010
self.assertEqual("line", f.line)

Lib/traceback.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,10 @@ def __len__(self):
301301
@property
302302
def line(self):
303303
if self._line is None:
304-
self._line = linecache.getline(self.filename, self.lineno).strip()
305-
return self._line
306-
304+
if self.lineno is None:
305+
return None
306+
self._line = linecache.getline(self.filename, self.lineno)
307+
return self._line.strip()
307308

308309
def walk_stack(f):
309310
"""Walk a stack yielding the frame and line number for each frame.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Take into account that ``lineno`` might be ``None`` in :class:`traceback.FrameSummary`.

0 commit comments

Comments
 (0)