diff --git a/pre_commit_hooks/debug_statement_hook.py b/pre_commit_hooks/debug_statement_hook.py index 7e6be95..43787c5 100644 --- a/pre_commit_hooks/debug_statement_hook.py +++ b/pre_commit_hooks/debug_statement_hook.py @@ -44,6 +44,11 @@ class DebugStatementParser(ast.NodeVisitor): self.breakpoints.append(st) def visit_Call(self, node: ast.Call) -> None: + if isinstance(node, ast.Call) and len(node.args): + if isinstance(node.args[0], ast.Constant) and node.args[0].value in DEBUG_STATEMENTS: + st = Debug(node.lineno, node.col_offset, node.args[0].value, 'imported') + self.breakpoints.append(st) + """python3.7+ breakpoint()""" if isinstance(node.func, ast.Name) and node.func.id == 'breakpoint': st = Debug(node.lineno, node.col_offset, node.func.id, 'called') diff --git a/tests/debug_statement_hook_test.py b/tests/debug_statement_hook_test.py index 5a8e0bb..56a3a03 100644 --- a/tests/debug_statement_hook_test.py +++ b/tests/debug_statement_hook_test.py @@ -26,6 +26,12 @@ def test_finds_debug_import_from_import(): assert visitor.breakpoints == [Debug(1, 0, 'pudb', 'imported')] +def test_finds_debug_import_when_using_dunder_import(): + visitor = DebugStatementParser() + visitor.visit(ast.parse('__import__("pdb").set_trace()')) + assert visitor.breakpoints == [Debug(1, 0, 'pdb', 'imported')] + + def test_finds_breakpoint(): visitor = DebugStatementParser() visitor.visit(ast.parse('breakpoint()'))