Skip to content

Commit

Permalink
feat: TRY002 also checks for Base Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
guilatrova committed Aug 19, 2024
1 parent d0a38d1 commit d2a6beb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/tests/analyzers_call_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ def test_raise_vanilla():

violations = analyzer.check(tree, "filename")

assert len(violations) == 1
violation = violations[0]
assert len(violations) == 2
exc_violation, base_exc_violation = violations

assert_vanilla(13, 8, violation)
assert_vanilla(14, 8, exc_violation)
assert_vanilla(34, 8, base_exc_violation)


def test_raise_long_args():
Expand Down
7 changes: 7 additions & 0 deletions src/tests/samples/violations/call_raise_vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Raising vanilla exception with custom message means it should be
customized.
"""

from somewhere import exceptions


Expand All @@ -25,3 +26,9 @@ def anotherfunc():
a = 1
if a == 1:
raise exceptions.Exception("Another except") # That's fine


def anotherfunc():
a = 1
if a == 1:
raise BaseException("Customer message - also an issue")
2 changes: 1 addition & 1 deletion src/tryceratops/analyzers/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CallRaiseVanillaAnalyzer(BaseRaiseCallableAnalyzer):
violation_code = codes.RAISE_VANILLA_CLASS

def _check_raise_callable(self, node: ast.Raise, exc: ast.Call, func: ast.Name) -> None:
if func.id == "Exception":
if func.id in ("BaseException", "Exception"):
self._mark_violation(node)


Expand Down

0 comments on commit d2a6beb

Please sign in to comment.