diff --git a/flake8_debugger.py b/flake8_debugger.py index c96aae6..d3f0094 100644 --- a/flake8_debugger.py +++ b/flake8_debugger.py @@ -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)) diff --git a/test_linter.py b/test_linter.py index c2e9594..2df37f3 100644 --- a/test_linter.py +++ b/test_linter.py @@ -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()')