Skip to content

Commit 366b949

Browse files
authored
gh-101517: make bdb avoid looking up in linecache with lineno=None (#101787)
1 parent 5d15224 commit 366b949

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Lib/bdb.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,10 @@ def format_stack_entry(self, frame_lineno, lprefix=': '):
570570
rv = frame.f_locals['__return__']
571571
s += '->'
572572
s += reprlib.repr(rv)
573-
line = linecache.getline(filename, lineno, frame.f_globals)
574-
if line:
575-
s += lprefix + line.strip()
573+
if lineno is not None:
574+
line = linecache.getline(filename, lineno, frame.f_globals)
575+
if line:
576+
s += lprefix + line.strip()
576577
return s
577578

578579
# The following methods can be called by clients to use

Lib/test/test_bdb.py

+6
Original file line numberDiff line numberDiff line change
@@ -1203,5 +1203,11 @@ def main():
12031203
tracer.runcall(tfunc_import)
12041204

12051205

1206+
class TestRegressions(unittest.TestCase):
1207+
def test_format_stack_entry_no_lineno(self):
1208+
# See gh-101517
1209+
Bdb().format_stack_entry((sys._getframe(), None))
1210+
1211+
12061212
if __name__ == "__main__":
12071213
unittest.main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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 commit comments

Comments
 (0)