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

don't crash when select / extend_select are None #261

Merged
merged 1 commit into from Jun 12, 2022
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 @@ -155,12 +155,13 @@ def should_warn(self, code):
return True

for i in range(2, len(code) + 1):
if code[:i] in self.options.select:
if self.options.select and code[:i] in self.options.select:
return True

# flake8 >=4.0: Also check for codes in extend_select
if (
hasattr(self.options, "extend_select")
and self.options.extend_select
and code[:i] in self.options.extend_select
):
return True
Expand Down
10 changes: 10 additions & 0 deletions tests/test_bugbear.py
Expand Up @@ -438,6 +438,16 @@ def test_b9_extend_select(self):
),
)

def test_b9_flake8_next_default_options(self):
filename = Path(__file__).absolute().parent / "b950.py"

# in flake8 next, unset select / extend_select will be `None` to
# signify the default values
mock_options = Namespace(select=None, extend_select=None)
bbc = BugBearChecker(filename=str(filename), options=mock_options)
errors = list(bbc.run())
self.assertEqual(errors, [])

def test_selfclean_bugbear(self):
filename = Path(__file__).absolute().parent.parent / "bugbear.py"
proc = subprocess.run(
Expand Down