https://github.com/python/cpython/commit/fddc24e4c85467f14075e94fd0d23d928ceb535f
commit: fddc24e4c85467f14075e94fd0d23d928ceb535f
branch: main
author: LloydZ <[email protected]>
committer: gaogaotiantian <[email protected]>
date: 2025-12-01T23:40:02-08:00
summary:

gh-141982: Fix pdb can't set breakpoints on async functions (#141983)

Co-authored-by: Tian Gao <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-11-30-04-28-30.gh-issue-141982.pxZct9.rst
M Lib/pdb.py
M Lib/test/test_pdb.py

diff --git a/Lib/pdb.py b/Lib/pdb.py
index 18cee7e9ae60e1..1506e3d4709817 100644
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -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:
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 8d582742499815..c097808e7fdc7c 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -4587,6 +4587,25 @@ def bar():
             ]))
             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
index 00000000000000..e5ec593dd6e65d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-11-30-04-28-30.gh-issue-141982.pxZct9.rst
@@ -0,0 +1 @@
+Allow :mod:`pdb` to set breakpoints on async functions with function names.

_______________________________________________
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