Skip to content

Commit 437c9d2

Browse files
authored
don't crash when select / extend_select are None (#261)
1 parent b1e4ef2 commit 437c9d2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Diff for: bugbear.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ def should_warn(self, code):
155155
return True
156156

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

161161
# flake8 >=4.0: Also check for codes in extend_select
162162
if (
163163
hasattr(self.options, "extend_select")
164+
and self.options.extend_select
164165
and code[:i] in self.options.extend_select
165166
):
166167
return True

Diff for: tests/test_bugbear.py

+10
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,16 @@ def test_b9_extend_select(self):
438438
),
439439
)
440440

441+
def test_b9_flake8_next_default_options(self):
442+
filename = Path(__file__).absolute().parent / "b950.py"
443+
444+
# in flake8 next, unset select / extend_select will be `None` to
445+
# signify the default values
446+
mock_options = Namespace(select=None, extend_select=None)
447+
bbc = BugBearChecker(filename=str(filename), options=mock_options)
448+
errors = list(bbc.run())
449+
self.assertEqual(errors, [])
450+
441451
def test_selfclean_bugbear(self):
442452
filename = Path(__file__).absolute().parent.parent / "bugbear.py"
443453
proc = subprocess.run(

0 commit comments

Comments
 (0)