Skip to content

Commit

Permalink
don't crash when select / extend_select are None (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Jun 12, 2022
1 parent b1e4ef2 commit 437c9d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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

0 comments on commit 437c9d2

Please sign in to comment.