Skip to content

Commit

Permalink
make B017 also apply to BaseException
Browse files Browse the repository at this point in the history
  • Loading branch information
r-downing committed Dec 15, 2023
1 parent a435545 commit 9fb4501
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ def check_for_b017(self, node):
)
and len(item_context.args) == 1
and isinstance(item_context.args[0], ast.Name)
and item_context.args[0].id == "Exception"
and item_context.args[0].id in {"Exception", "BaseException"}
and not item.optional_vars
):
self.errors.append(B017(node.lineno, node.col_offset))
Expand Down
10 changes: 9 additions & 1 deletion tests/b017.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Should emit:
B017 - on lines 24, 26, 28, 31 and 32.
B017 - on lines 24, 26, 28, 31, 32, 73, 75, 77.
"""

import asyncio
Expand Down Expand Up @@ -68,3 +68,11 @@ def raises_with_absolute_reference(self):
Foo()
with raises(asyncio.CancelledError):
Foo()

def raises_base_exception(self):
with self.assertRaises(BaseException):
Foo()
with pytest.raises(BaseException):
Foo()
with raises(BaseException):
Foo()
10 changes: 9 additions & 1 deletion tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,15 @@ def test_b017(self):
filename = Path(__file__).absolute().parent / "b017.py"
bbc = BugBearChecker(filename=str(filename))
errors = list(bbc.run())
expected = self.errors(B017(26, 8), B017(28, 8), B017(30, 8), B017(32, 8))
expected = self.errors(
B017(26, 8),
B017(28, 8),
B017(30, 8),
B017(32, 8),
B017(73, 8),
B017(75, 8),
B017(77, 8),
)
self.assertEqual(errors, expected)

def test_b018_functions(self):
Expand Down

0 comments on commit 9fb4501

Please sign in to comment.