Skip to content

Commit fddc24e

Browse files
gh-141982: Fix pdb can't set breakpoints on async functions (#141983)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
1 parent 2dc28eb commit fddc24e

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Lib/pdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def find_first_executable_line(code):
130130
return code.co_firstlineno
131131

132132
def find_function(funcname, filename):
133-
cre = re.compile(r'def\s+%s(\s*\[.+\])?\s*[(]' % re.escape(funcname))
133+
cre = re.compile(r'(?:async\s+)?def\s+%s(\s*\[.+\])?\s*[(]' % re.escape(funcname))
134134
try:
135135
fp = tokenize.open(filename)
136136
except OSError:

Lib/test/test_pdb.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4587,6 +4587,25 @@ def bar():
45874587
]))
45884588
self.assertIn('break in bar', stdout)
45894589

4590+
@unittest.skipIf(SKIP_CORO_TESTS, "Coroutine tests are skipped")
4591+
def test_async_break(self):
4592+
script = """
4593+
import asyncio
4594+
4595+
async def main():
4596+
pass
4597+
4598+
asyncio.run(main())
4599+
"""
4600+
commands = """
4601+
break main
4602+
continue
4603+
quit
4604+
"""
4605+
stdout, stderr = self.run_pdb_script(script, commands)
4606+
self.assertRegex(stdout, r"Breakpoint 1 at .*main\.py:5")
4607+
self.assertIn("pass", stdout)
4608+
45904609
def test_issue_59000(self):
45914610
script = """
45924611
def foo():
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow :mod:`pdb` to set breakpoints on async functions with function names.

0 commit comments

Comments
 (0)