8000 gh-101517: make bdb avoid looking up in linecache with lineno=None (G… · python/cpython@6d8ef96 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6d8ef96

Browse files
gh-101517: make bdb avoid looking up in linecache with lineno=None (GH-101787)
(cherry picked from commit 366b949) Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
1 parent b653fce commit 6d8ef96

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

Lib/bdb.py

Lines changed: 4 additions & 3 deletions
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

Lines changed: 6 additions & 0 deletions
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()
Lines changed: 1 addition & 0 deletions
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)
0