]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141982: Fix pdb can't set breakpoints on async functions (#141983)
authorLloydZ <35182391+cocolato@users.noreply.github.com>
Tue, 2 Dec 2025 07:40:02 +0000 (15:40 +0800)
committerGitHub <noreply@github.com>
Tue, 2 Dec 2025 07:40:02 +0000 (23:40 -0800)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2025-11-30-04-28-30.gh-issue-141982.pxZct9.rst [new file with mode: 0644]

index 18cee7e9ae60e169292c8c71fa66ce31d6184d29..1506e3d4709817011509326dd5dc5bcdd1731895 100644 (file)
@@ -130,7 +130,7 @@ def find_first_executable_line(code):
     return code.co_firstlineno
 
 def find_function(funcname, filename):
-    cre = re.compile(r'def\s+%s(\s*\[.+\])?\s*[(]' % re.escape(funcname))
+    cre = re.compile(r'(?:async\s+)?def\s+%s(\s*\[.+\])?\s*[(]' % re.escape(funcname))
     try:
         fp = tokenize.open(filename)
     except OSError:
index 8d5827424998154341b4c4868226fb9bdeeda614..c097808e7fdc7cf0e8438ae695729556f86a1688 100644 (file)
@@ -4587,6 +4587,25 @@ def bœr():
             ]))
             self.assertIn('break in bar', stdout)
 
+    @unittest.skipIf(SKIP_CORO_TESTS, "Coroutine tests are skipped")
+    def test_async_break(self):
+        script = """
+            import asyncio
+
+            async def main():
+                pass
+
+            asyncio.run(main())
+        """
+        commands = """
+            break main
+            continue
+            quit
+        """
+        stdout, stderr = self.run_pdb_script(script, commands)
+        self.assertRegex(stdout, r"Breakpoint 1 at .*main\.py:5")
+        self.assertIn("pass", stdout)
+
     def test_issue_59000(self):
         script = """
             def foo():
diff --git a/Misc/NEWS.d/next/Library/2025-11-30-04-28-30.gh-issue-141982.pxZct9.rst b/Misc/NEWS.d/next/Library/2025-11-30-04-28-30.gh-issue-141982.pxZct9.rst
new file mode 100644 (file)
index 0000000..e5ec593
--- /dev/null
@@ -0,0 +1 @@
+Allow :mod:`pdb` to set breakpoints on async functions with function names.