Skip to content

Commit 7c3f665

Browse files
committed
check for print debug statement
1 parent f4e0254 commit 7c3f665

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pre_commit_hooks/debug_statement_hook.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
'wdb',
2121
}
2222

23+
DEBUG_CALL_STATEMENTS = {
24+
'breakpoint',
25+
'print'
26+
}
27+
2328

2429
class Debug(NamedTuple):
2530
line: int
@@ -45,7 +50,7 @@ def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
4550

4651
def visit_Call(self, node: ast.Call) -> None:
4752
"""python3.7+ breakpoint()"""
48-
if isinstance(node.func, ast.Name) and node.func.id == 'breakpoint':
53+
if isinstance(node.func, ast.Name) and node.func.id in DEBUG_CALL_STATEMENTS:
4954
st = Debug(node.lineno, node.col_offset, node.func.id, 'called')
5055
self.breakpoints.append(st)
5156
self.generic_visit(node)

tests/debug_statement_hook_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ def test_finds_breakpoint():
3030
visitor = DebugStatementParser()
3131
visitor.visit(ast.parse('breakpoint()'))
3232
assert visitor.breakpoints == [Debug(1, 0, 'breakpoint', 'called')]
33+
34+
35+
def test_finds_print():
36+
visitor = DebugStatementParser()
37+
visitor.visit(ast.parse('print()'))
38+
assert visitor.breakpoints == [Debug(1, 0, 'print', 'called')]
3339

3440

3541
def test_returns_one_for_failing_file(tmpdir):

0 commit comments

Comments
 (0)