[Python-checkins] gh-101517: make bdb avoid looking up in linecache with lineno=None (GH-101787)

miss-islington webhook-mailer at python.org
Fri Feb 10 12:24:38 EST 2023


https://github.com/python/cpython/commit/6d8ef9680689823229106c22aa74e1c549a250ec
commit: 6d8ef9680689823229106c22aa74e1c549a250ec
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2023-02-10T09:24:30-08:00
summary:

gh-101517: make bdb avoid looking up in linecache with lineno=None (GH-101787)

(cherry picked from commit 366b94905869d680b3f1d4801fb497e78811e511)

Co-authored-by: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2023-02-10-16-02-29.gh-issue-101517.r7S2u8.rst
M Lib/bdb.py
M Lib/test/test_bdb.py

diff --git a/Lib/bdb.py b/Lib/bdb.py
index 81fbb8514acb..7f9b09514ffd 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -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
diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py
index 87a5ac308a12..042c2daea7f7 100644
--- a/Lib/test/test_bdb.py
+++ b/Lib/test/test_bdb.py
@@ -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()
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 000000000000..a5f6bdfa5ac2
--- /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.



More information about the Python-checkins mailing list