Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make B017 also apply to BaseException #439

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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