Skip to content

Commit 85716d2

Browse files
cocolatogaogaotiantian
authored andcommitted
[3.13] gh-59000: Fix pdb breakpoint resolution for class methods when module not imported (GH-141949)
(cherry picked from commit 5e58548) Co-authored-by: LloydZ <35182391+cocolato@users.noreply.github.com>
1 parent 01393ff commit 85716d2

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

Lib/pdb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,9 @@ def lineinfo(self, identifier):
12621262
f = self.lookupmodule(parts[0])
12631263
if f:
12641264
fname = f
1265-
item = parts[1]
1265+
item = parts[1]
1266+
else:
1267+
return failed
12661268
answer = find_function(item, self.canonic(fname))
12671269
return answer or failed
12681270

Lib/test/test_pdb.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4013,6 +4013,54 @@ def f(x):
40134013
self.assertIn('42', stdout)
40144014
self.assertIn('return x + 1', stdout)
40154015

4016+
def test_zipimport(self):
4017+
with os_helper.temp_dir() as temp_dir:
4018+
os.mkdir(os.path.join(temp_dir, 'source'))
4019+
zipmodule = textwrap.dedent(
4020+
"""
4021+
def bar():
4022+
pass
4023+
"""
4024+
)
4025+
script = textwrap.dedent(
4026+
f"""
4027+
import sys; sys.path.insert(0, {repr(os.path.join(temp_dir, 'zipmodule.zip'))})
4028+
import foo
4029+
foo.bar()
4030+
"""
4031+
)
4032+
4033+
with zipfile.ZipFile(os.path.join(temp_dir, 'zipmodule.zip'), 'w') as zf:
4034+
zf.writestr('foo.py', zipmodule)
4035+
with open(os.path.join(temp_dir, 'script.py'), 'w') as f:
4036+
f.write(script)
4037+
4038+
stdout, _ = self._run_pdb([os.path.join(temp_dir, 'script.py')], '\n'.join([
4039+
'n',
4040+
'n',
4041+
'b foo.bar',
4042+
'c',
4043+
'p f"break in {$_frame.f_code.co_name}"',
4044+
'q'
4045+
]))
4046+
self.assertIn('break in bar', stdout)
4047+
4048+
def test_issue_59000(self):
4049+
script = """
4050+
def foo():
4051+
pass
4052+
4053+
class C:
4054+
def foo(self):
4055+
pass
4056+
"""
4057+
commands = """
4058+
break C.foo
4059+
quit
4060+
"""
4061+
stdout, stderr = self.run_pdb_script(script, commands)
4062+
self.assertIn("The specified object 'C.foo' is not a function", stdout)
4063+
40164064

40174065
class ChecklineTests(unittest.TestCase):
40184066
def setUp(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :mod:`pdb` breakpoint resolution for class methods when the module defining the class is not imported.

0 commit comments

Comments
 (0)