]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-101517: make bdb avoid looking up in linecache with lineno=None (GH-101787)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 10 Feb 2023 17:24:30 +0000 (09:24 -0800)
committerGitHub <noreply@github.com>
Fri, 10 Feb 2023 17:24:30 +0000 (09:24 -0800)
(cherry picked from commit 366b94905869d680b3f1d4801fb497e78811e511)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Lib/bdb.py
Lib/test/test_bdb.py
Misc/NEWS.d/next/Library/2023-02-10-16-02-29.gh-issue-101517.r7S2u8.rst [new file with mode: 0644]

index 81fbb8514acb6f47d3e404f1068f72a046a6bf68..7f9b09514ffd00ea9cda0d56a014a79ea16ada21 100644 (file)
@@ -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
index 87a5ac308a12df4373ab908c7c6bd00d8b74e95f..042c2daea7f7970ddc53be8f85ef09f80fe00086 100644 (file)
@@ -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 (file)
index 0000000..a5f6bdf
--- /dev/null
@@ -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.