Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,9 @@ def lineinfo(self, identifier):
f = self.lookupmodule(parts[0])
if f:
fname = f
item = parts[1]
item = parts[1]
else:
return failed
answer = find_function(item, self.canonic(fname))
return answer or failed

Expand Down
29 changes: 29 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4587,6 +4587,35 @@ def bar():
]))
self.assertIn('break in bar', stdout)

def test_issue_59000(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are testing the wrong thing. You should test C.foo, not C.c_foo. So a good practice is to confirm that your test fails before your fix and passes after. Also from the other PR - do not test what you don't want to. Make the test minimal. C.c_foo is not important here. Let's simplify the test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are testing the wrong thing. You should test C.foo, not C.c_foo. So a good practice is to confirm that your test fails before your fix and passes after. Also from the other PR - do not test what you don't want to. Make the test minimal. C.c_foo is not important here. Let's simplify the test.

Thank you for taking the time to review. I have made some changes.

script = """
def foo():
test_str = "break foo"
class C:
def foo(self):
test_str = "break C.foo"
foo()
C().foo()
"""
commands = """
break foo
break C.foo
continue
break C.foo
continue
quit
"""
stdout, stderr = self.run_pdb_script(script, commands)
res_lines = [x.strip() for x in stdout.splitlines()]
# can't set breakpoint before class C is defined, and gives an error
self.assertIn("The specified object 'C.foo' is not a function", res_lines[3])
# can set correctly after the class C is defined
self.assertRegex(res_lines[6], r"Breakpoint 2 at .*main\.py:7")
self.assertIn('test_str = "break C.foo"', res_lines[8])



class ChecklineTests(unittest.TestCase):
def setUp(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :mod:`pdb` breakpoint resolution for class methods when the module defining the class is not imported.
Loading