Skip to content

Commit

Permalink
works on pdb
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Dec 28, 2023
1 parent 06bd59b commit bf5cef1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/core_codemods/remove_debug_breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ def leave_Expr(
) == "breakpoint" and self.is_builtin_function(call_node):
self.report_change(original_node)
return cst.RemovalSentinel.REMOVE
if self.find_base_name(call_node) == "pdb.set_trace":
self.remove_unused_import(call_node)
self.report_change(original_node)
return cst.RemovalSentinel.REMOVE

return original_node
20 changes: 17 additions & 3 deletions tests/codemods/test_remove_debug_breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ def something():
self.run_and_assert(tmpdir, dedent(input_code), dedent(expected))
assert len(self.file_context.codemod_changes) == 1

def test_builtin_breakpoint_multiple_statements(self, tmpdir):
input_code = """\
def something():
var = 1
print(var); breakpoint()
something()
"""
expected = """\
def something():
var = 1
print(var);
something()
"""
self.run_and_assert(tmpdir, dedent(input_code), dedent(expected))
assert len(self.file_context.codemod_changes) == 1

def test_inline_pdb(self, tmpdir):
input_code = """\
def something():
Expand Down Expand Up @@ -57,7 +73,7 @@ def something():

def test_pdb_from_import(self, tmpdir):
input_code = """\
from pdb import set_trace()
from pdb import set_trace
def something():
var = 1
set_trace()
Expand All @@ -70,5 +86,3 @@ def something():
"""
self.run_and_assert(tmpdir, dedent(input_code), dedent(expected))
assert len(self.file_context.codemod_changes) == 1

# what about line line print(1); breakpoint

0 comments on commit bf5cef1

Please sign in to comment.