Skip to content

Commit 1e30bd3

Browse files
committed
#9230: allow Pdb.checkline() to be called without a current frame, for setting breakpoints before starting debugging.
1 parent a91a94b commit 1e30bd3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Lib/pdb.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,10 @@ def checkline(self, filename, lineno):
675675
Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank
676676
line or EOF). Warning: testing is not comprehensive.
677677
"""
678-
line = linecache.getline(filename, lineno, self.curframe.f_globals)
678+
# this method should be callable before starting debugging, so default
679+
# to "no globals" if there is no current frame
680+
globs = self.curframe.f_globals if hasattr(self, 'curframe') else None
681+
line = linecache.getline(filename, lineno, globs)
679682
if not line:
680683
print('End of file', file=self.stdout)
681684
return 0
@@ -1514,7 +1517,7 @@ def main():
15141517
# changed by the user from the command line. There is a "restart" command
15151518
# which allows explicit specification of command line arguments.
15161519
pdb = Pdb()
1517-
while 1:
1520+
while True:
15181521
try:
15191522
pdb._runscript(mainpyfile)
15201523
if pdb._user_requested_quit:

0 commit comments

Comments
 (0)