Skip to content

Commit

Permalink
gh-101517: make bdb avoid looking up in linecache with lineno=None (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel authored Feb 10, 2023
1 parent 5d15224 commit 366b949
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Lib/bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,10 @@ def format_stack_entry(self, frame_lineno, lprefix=': '):
rv = frame.f_locals['__return__']
s += '->'
s += reprlib.repr(rv)
line = linecache.getline(filename, lineno, frame.f_globals)
if line:
s += lprefix + line.strip()
if lineno is not None:
line = linecache.getline(filename, lineno, frame.f_globals)
if line:
s += lprefix + line.strip()
return s

# The following methods can be called by clients to use
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,5 +1203,11 @@ def main():
tracer.runcall(tfunc_import)


class TestRegressions(unittest.TestCase):
def test_format_stack_entry_no_lineno(self):
# See gh-101517
Bdb().format_stack_entry((sys._getframe(), None))


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug where :mod:`bdb` looks up the source line with :mod:`linecache` with a ``lineno=None``, which causes it to fail with an unhandled exception.

0 comments on commit 366b949

Please sign in to comment.