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

Add another hasattr() check to b017 visit #165

Merged
merged 2 commits into from Apr 1, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion bugbear.py
Expand Up @@ -439,7 +439,8 @@ def check_for_b017(self, node):
item = node.items[0]
item_context = item.context_expr
if (
hasattr(item_context.func, "attr")
hasattr(item_context, "func")
and hasattr(item_context.func, "attr") # noqa W503
and item_context.func.attr == "assertRaises" # noqa W503
and len(item_context.args) == 1 # noqa W503
and item_context.args[0].id == "Exception" # noqa W503
Expand Down
8 changes: 8 additions & 0 deletions tests/b017.py
Expand Up @@ -5,6 +5,14 @@
import unittest


CONSTANT = True


def something_else() -> None:
for i in (1, 2, 3):
print(i)


class Foobar(unittest.TestCase):
def evil_raises(self) -> None:
with self.assertRaises(Exception):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bugbear.py
Expand Up @@ -210,7 +210,7 @@ def test_b017(self):
filename = Path(__file__).absolute().parent / "b017.py"
bbc = BugBearChecker(filename=str(filename))
errors = list(bbc.run())
expected = self.errors(B017(10, 8))
expected = self.errors(B017(18, 8))
self.assertEqual(errors, expected)

def test_b301_b302_b305(self):
Expand Down