Skip to content

Commit

Permalink
Detect __import__ debugger statements (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
sliverc authored and JBKahn committed Feb 11, 2018
1 parent 3eaae1e commit d1b5429
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flake8_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def visit_Call(self, node):
debugger_method_names = chain(debuggers.values(), self.debuggers_traces_names.values())
is_debugger_attribute = getattr(node.func, "attr", None) in list(debugger_method_names)
if is_debugger_attribute:
caller = node.func.value.id
caller = getattr(node.func.value, "id", None)
entry = self.debuggers_used.setdefault((node.lineno, node.col_offset), [])
if caller in self.debuggers_names.values():
entry.append('{0} trace found: {1}.{2} used'.format(DEBUGGER_ERROR_CODE, caller, node.func.attr))
Expand Down
9 changes: 9 additions & 0 deletions test_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def test_catches_simple_debugger_when_called_off_lib(self):

assert result == expected_result

def test_catches_simple_debugger_when_called_off_global(self):
result = check_code_for_debugger_statements("__import__('ipdb').set_trace()")

expected_result = [
{'line': 1, 'message': 'T002 trace found: set_trace used', 'col': 0},
]

assert result == expected_result

@pytest.mark.skipif(True, reason="Not supported just yet")
def test_catches_simple_debugger_when_called_off_var(self):
result = check_code_for_debugger_statements('import ipdb\ntest = ipdb.set_trace\ntest()')
Expand Down

0 comments on commit d1b5429

Please sign in to comment.