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

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
LloydZ 2025-12-02 15:40:02 +08:00 committed by GitHub
parent 2dc28eb8b0
commit fddc24e4c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View 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:

View file

@ -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():

View file

@ -0,0 +1 @@
Allow :mod:`pdb` to set breakpoints on async functions with function names.