Skip to content

Commit 9b38570

Browse files
committed
Don't crash if we're raising an attribute as an exception.
Fixes nhoad#9.
1 parent f186522 commit 9b38570

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

flake8_unused_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,18 @@ def is_stub_function(function: FunctionTypes) -> bool:
176176
return True
177177

178178
if isinstance(statement, ast.Raise):
179+
# raise NotImplementedError()
179180
if (
180181
isinstance(statement.exc, ast.Call)
182+
and hasattr(statement.exc.func, "id")
181183
and statement.exc.func.id == "NotImplementedError" # type: ignore
182184
):
183185
return True
184186

187+
# raise NotImplementedError
185188
elif (
186189
isinstance(statement.exc, ast.Name)
190+
and hasattr(statement.exc, "id")
187191
and statement.exc.id == "NotImplementedError"
188192
):
189193
return True

test_unused_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def test_get_decorator_names(function, expected_result):
121121
("def foo(): raise NotImplementedError()", True),
122122
("def foo(): raise NotImplementedError", True),
123123
("def foo(): raise SomethingElse()", False),
124+
("def foo(): raise object.error()", False),
125+
("def foo(): raise object.error", False),
126+
("def foo(): raise value", False),
127+
("def foo(): raise 'cool string'", False),
124128
("def foo(): raise", False),
125129
("lambda: ...", True),
126130
("lambda: 5", False),

0 commit comments

Comments
 (0)