summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/bdb.py7
-rw-r--r--Lib/test/test_bdb.py6
-rw-r--r--Misc/NEWS.d/next/Library/2023-02-10-16-02-29.gh-issue-101517.r7S2u8.rst1
3 files changed, 11 insertions, 3 deletions
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 81fbb85..7f9b095 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -570,9 +570,10 @@ class Bdb:
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
diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py
index 87a5ac3..042c2da 100644
--- a/Lib/test/test_bdb.py
+++ b/Lib/test/test_bdb.py
@@ -1203,5 +1203,11 @@ class IssuesTestCase(BaseTestCase):
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()
diff --git a/Misc/NEWS.d/next/Library/2023-02-10-16-02-29.gh-issue-101517.r7S2u8.rst b/Misc/NEWS.d/next/Library/2023-02-10-16-02-29.gh-issue-101517.r7S2u8.rst
new file mode 100644
index 0000000..a5f6bdf
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-02-10-16-02-29.gh-issue-101517.r7S2u8.rst
@@ -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.