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

(cherry picked from commit 366b949058)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2023-02-10 09:26:27 -08:00 committed by GitHub
parent 4b8d2a1b40
commit b0bba7ad14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View 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

View 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()

View file

@ -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.