https://github.com/python/cpython/commit/5b33e9c1763813c459f9857ad3c168692fb95148
commit: 5b33e9c1763813c459f9857ad3c168692fb95148
branch: 3.14
author: Tian Gao <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2026-05-06T04:56:54Z
summary:

[3.14] gh-148615: Handle `--` separator in pdb argument parsing (GH-1… (#149442)

[3.14] gh-148615: Handle `--` separator in pdb argument parsing (GH-148624)
(cherry picked from commit 970b0433f498fd0d048b1f50229a7f0fb4d9e07a)

Co-authored-by: Shrey Naithani <[email protected]>

files:
A Misc/NEWS.d/next/Library/2026-04-15-16-08-12.gh-issue-148615.Uvx50R.rst
M Lib/pdb.py
M Lib/test/test_pdb.py

diff --git a/Lib/pdb.py b/Lib/pdb.py
index 903baeb85c87c0..7dcd0cb1b37e71 100644
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -3611,6 +3611,10 @@ def parse_args():
         opt_module = parser.parse_args(args[:2])
         opts.module = opt_module.module
         args = args[2:]
+    elif args[0] == '--':
+        args.pop(0)
+        if not args:
+            parser.error("missing script or module to run")
     elif args[0].startswith('-'):
         # Invalid argument before the script name.
         invalid_args = list(itertools.takewhile(lambda a: a.startswith('-'), 
args))
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 16d1015cc4fca1..78d3b5ec0dc735 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -4643,6 +4643,27 @@ def bar():
             ]))
             self.assertIn('break in bar', stdout)
 
+    def test_end_of_options_separator(self):
+        # gh-148615: Test parsing when '--' separator is used
+        script = "import sys; print(f'ARGS: {sys.argv[1:]}')"
+        with open(os_helper.TESTFN, 'w', encoding='utf-8') as f:
+            f.write(script)
+        stdout, _ = self._run_pdb(['--', os_helper.TESTFN, '-foo'], 'c\nq')
+        self.assertIn("ARGS: ['-foo']", stdout)
+        stdout, _ = self._run_pdb(['-c', 'continue', '--', os_helper.TESTFN, 
'-c', 'foo'], 'q')
+        self.assertIn("ARGS: ['-c', 'foo']", stdout)
+        stdout, stderr = self._run_pdb(['--'], 'q', expected_returncode=2)
+        self.assertIn("missing script or module to run", stderr)
+        stdout, stderr = self._run_pdb(['-x', '--', os_helper.TESTFN], 'q', 
expected_returncode=2)
+        self.assertIn("unrecognized arguments: -x", stderr)
+        stdout, _ = self._run_pdb([os_helper.TESTFN, '--', 'arg'], 'c\nq')
+        self.assertIn("ARGS: ['--', 'arg']", stdout)
+        with os_helper.temp_cwd():
+            with open('mymod.py', 'w', encoding='utf-8') as f:
+                f.write(script)
+            stdout, _ = self._run_pdb(['-m', 'mymod', '--', 'arg'], 'c\nq')
+            self.assertIn("ARGS: ['--', 'arg']", stdout)
+
     def test_issue_59000(self):
         script = """
             def foo():
diff --git 
a/Misc/NEWS.d/next/Library/2026-04-15-16-08-12.gh-issue-148615.Uvx50R.rst 
b/Misc/NEWS.d/next/Library/2026-04-15-16-08-12.gh-issue-148615.Uvx50R.rst
new file mode 100644
index 00000000000000..f023f0141889a6
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-04-15-16-08-12.gh-issue-148615.Uvx50R.rst
@@ -0,0 +1 @@
+Fix :mod:`pdb` to accept standard -- end of options separator. Reported by 
haampie. Patched by Shrey Naithani.

_______________________________________________
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]

Reply via email to