https://github.com/python/cpython/commit/90b1406b881aa0a57ce3a73c402b73b79138b7e0 commit: 90b1406b881aa0a57ce3a73c402b73b79138b7e0 branch: 3.12 author: Miss Islington (bot) <[email protected]> committer: gaogaotiantian <[email protected]> date: 2024-10-15T16:29:05Z summary:
[3.12] gh-100141: Allow pdb to deal with empty file (GH-125425) (#125537) gh-100141: Allow pdb to deal with empty file (GH-125425) (cherry picked from commit bb9604b62ae7f043594ffea9287f9213067cc7fb) Co-authored-by: Tian Gao <[email protected]> files: A Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst M Lib/pdb.py M Lib/test/test_pdb.py diff --git a/Lib/pdb.py b/Lib/pdb.py index 89cf975164ac04..559517813cf600 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -321,8 +321,7 @@ def user_call(self, frame, argument_list): def user_line(self, frame): """This function is called when we stop or break at this line.""" if self._wait_for_mainpyfile: - if (self.mainpyfile != self.canonic(frame.f_code.co_filename) - or frame.f_lineno <= 0): + if (self.mainpyfile != self.canonic(frame.f_code.co_filename)): return self._wait_for_mainpyfile = False if self.bp_commands(frame): diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 6da82fe04c0eaa..1542bb3bee1aea 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -2754,6 +2754,16 @@ def _create_fake_frozen_module(): # verify that pdb found the source of the "frozen" function self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found") + def test_empty_file(self): + script = '' + commands = 'q\n' + # We check that pdb stopped at line 0, but anything reasonable + # is acceptable here, as long as it does not halt + stdout, _ = self.run_pdb_script(script, commands) + self.assertIn('main.py(0)', stdout) + stdout, _ = self.run_pdb_module(script, commands) + self.assertIn('__main__.py(0)', stdout) + def test_non_utf8_encoding(self): script_dir = os.path.join(os.path.dirname(__file__), 'encoded_modules') for filename in os.listdir(script_dir): diff --git a/Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst b/Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst new file mode 100644 index 00000000000000..c366b0ad4040d3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst @@ -0,0 +1 @@ +Fixed the bug where :mod:`pdb` will be stuck in an infinite loop when debugging an empty file. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: [email protected]
