diff -r 19e199038704 Lib/pdb.py --- a/Lib/pdb.py Tue Oct 25 15:38:28 2016 +0300 +++ b/Lib/pdb.py Tue Oct 25 14:07:06 2016 +0100 @@ -748,7 +748,10 @@ """ # this method should be callable before starting debugging, so default # to "no globals" if there is no current frame - globs = self.curframe.f_globals if hasattr(self, 'curframe') else None + globs = None + if getattr(self, 'curframe', None) is not None: + globs = self.curframe.f_globals + line = linecache.getline(filename, lineno, globs) if not line: self.message('End of file') diff -r 19e199038704 Lib/test/test_pdb.py --- a/Lib/test/test_pdb.py Tue Oct 25 15:38:28 2016 +0300 +++ b/Lib/test/test_pdb.py Tue Oct 25 14:07:06 2016 +0100 @@ -1110,6 +1110,16 @@ if save_home is not None: os.environ['HOME'] = save_home + def test_reset_checkline(self): + # Ensure that checkline() can be called after reset() + with open(support.TESTFN, 'w') as f: + f.write("print(123)") + + deb = pdb.Pdb() + self.assertEqual(deb.checkline(support.TESTFN, 1), 1) + deb.reset() + self.assertEqual(deb.checkline(support.TESTFN, 1), 1) + def tearDown(self): support.unlink(support.TESTFN)