https://github.com/python/cpython/commit/63b6ec31c44bc91f748a39daf4f65ef9ad25d21b
commit: 63b6ec31c44bc91f748a39daf4f65ef9ad25d21b
branch: main
author: Tian Gao <gaogaotiant...@hotmail.com>
committer: gaogaotiantian <gaogaotiant...@hotmail.com>
date: 2025-03-04T11:35:47-05:00
summary:

gh-82987: Stop on calling frame unconditionally for inline breakpoints (#130493)

files:
A Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst
M Doc/library/pdb.rst
M Doc/whatsnew/3.14.rst
M Lib/bdb.py
M Lib/test/test_pdb.py

diff --git a/Doc/library/pdb.rst b/Doc/library/pdb.rst
index bdd89d127491a5..b31625e6b0082f 100644
--- a/Doc/library/pdb.rst
+++ b/Doc/library/pdb.rst
@@ -245,6 +245,10 @@ access further features, you have to do this yourself:
    .. versionadded:: 3.14
       Added the *mode* argument.
 
+   .. versionchanged:: 3.14
+      Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will
+      always stop the program at calling frame, ignoring the *skip* pattern 
(if any).
+
    .. method:: run(statement, globals=None, locals=None)
                runeval(expression, globals=None, locals=None)
                runcall(function, *args, **kwds)
diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst
index aa802faae50b12..7b1a30d5a873ae 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -780,6 +780,11 @@ pdb
   the quit and call :func:`sys.exit`, instead of raising :exc:`bdb.BdbQuit`.
   (Contributed by Tian Gao in :gh:`124704`.)
 
+* Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will
+  always stop the program at calling frame, ignoring the ``skip`` pattern
+  (if any).
+  (Contributed by Tian Gao in :gh:`130493`.)
+
 
 pickle
 ------
diff --git a/Lib/bdb.py b/Lib/bdb.py
index a741628e32a981..2463cc217c6d75 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -215,10 +215,13 @@ def dispatch_opcode(self, frame, arg):
         If the debugger stops on the current opcode, invoke
         self.user_opcode(). Raise BdbQuit if self.quitting is set.
         Return self.trace_dispatch to continue tracing in this scope.
+
+        Opcode event will always trigger the user callback. For now the only
+        opcode event is from an inline set_trace() and we want to stop there
+        unconditionally.
         """
-        if self.stop_here(frame) or self.break_here(frame):
-            self.user_opcode(frame)
-            if self.quitting: raise BdbQuit
+        self.user_opcode(frame)
+        if self.quitting: raise BdbQuit
         return self.trace_dispatch
 
     # Normally derived classes don't override the following
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 7a99c1db84b439..7ecb8d4cd4d5fa 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -4342,6 +4342,28 @@ def test_quit(self):
         # The quit prompt should be printed exactly twice
         self.assertEqual(stdout.count("Quit anyway"), 2)
 
+    def test_set_trace_with_skip(self):
+        """GH-82897
+        Inline set_trace() should break unconditionally. This example is a
+        bit oversimplified, but as `pdb.set_trace()` uses the previous Pdb
+        instance, it's possible that we had a previous pdb instance with
+        skip values when we use `pdb.set_trace()` - it would be confusing
+        to users when such inline breakpoints won't break immediately.
+        """
+        script = textwrap.dedent("""
+            import pdb
+            def foo():
+                x = 40 + 2
+                pdb.Pdb(skip=['__main__']).set_trace()
+            foo()
+        """)
+        commands = """
+            p x
+            c
+        """
+        stdout, _ = self._run_script(script, commands)
+        self.assertIn("42", stdout)
+
 
 @support.force_not_colorized_test_class
 @support.requires_subprocess()
diff --git 
a/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst 
b/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst
new file mode 100644
index 00000000000000..0cfc7cf0cf7163
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-02-24-01-49-11.gh-issue-82987.vHfQlG.rst
@@ -0,0 +1 @@
+Inline breakpoints like :func:`breakpoint` or :func:`pdb.set_trace` will 
always stop the program at calling frame, ignoring the ``skip`` pattern (if 
any).

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to