diff --git a/README.rst b/README.rst index 4bee724..bde5850 100644 --- a/README.rst +++ b/README.rst @@ -279,6 +279,14 @@ MIT Change Log ---------- +22.6.22 +~~~~~~~~~~ + +* Don't crash when select / extend_select are None (#261) +* Ignore lambda arguments for B020 (#259) +* Fix missing space typos in B021, B022 error messages (#257) + + 22.4.25 ~~~~~~~~~~ diff --git a/bugbear.py b/bugbear.py index 4201fbc..f1dcf9e 100644 --- a/bugbear.py +++ b/bugbear.py @@ -12,7 +12,7 @@ import attr import pycodestyle -__version__ = "22.4.25" +__version__ = "22.6.22" LOG = logging.getLogger("flake8.bugbear") CONTEXTFUL_NODES = ( @@ -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 @@ -824,6 +825,11 @@ def visit_DictComp(self, node): def visit_comprehension(self, node): self.visit(node.iter) + def visit_Lambda(self, node): + self.visit(node.body) + for lambda_arg in node.args.args: + self.names.pop(lambda_arg.arg, None) + error = namedtuple("error", "lineno col message type vars") Error = partial(partial, error, type=BugBearChecker, vars=()) @@ -1023,14 +1029,14 @@ def visit_comprehension(self, node): ) B021 = Error( message=( - "B021 f-string used as docstring." + "B021 f-string used as docstring. " "This will be interpreted by python as a joined string rather than a docstring." ) ) B022 = Error( message=( - "B022 No arguments passed to `contextlib.suppress`." - "No exceptions will be suppressed and therefore this" + "B022 No arguments passed to `contextlib.suppress`. " + "No exceptions will be suppressed and therefore this " "context manager is redundant." ) ) diff --git a/tests/b020.py b/tests/b020.py index 4f30984..9bdc4b4 100644 --- a/tests/b020.py +++ b/tests/b020.py @@ -35,3 +35,6 @@ # However we still call out reassigning the iterable in the comprehension. for vars in [i for i in vars]: print(vars) + +for var in sorted(range(10), key=lambda var: var.real): + print(var) diff --git a/tests/test_bugbear.py b/tests/test_bugbear.py index a974cf4..12469e6 100644 --- a/tests/test_bugbear.py +++ b/tests/test_bugbear.py @@ -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(