Skip to content

Commit

Permalink
Skip B905 automaically if python <3.10 is used
Browse files Browse the repository at this point in the history
Closes PyCQA#320
  • Loading branch information
kasium committed Dec 12, 2022
1 parent 815ab98 commit 4d8d807
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ for details.

**B905**: ``zip()`` without an explicit `strict=` parameter set. ``strict=True`` causes the resulting iterator
to raise a ``ValueError`` if the arguments are exhausted at differing lengths. The ``strict=`` argument
was added in Python 3.10, so don't enable this flag for code that should work on <3.10.
was added in Python 3.10, so the check is disabled when running on python <3.10.
For more information: https://peps.python.org/pep-0618/

**B906**: ``visit_`` function with no further call to a ``visit`` function. This is often an error, and will stop the visitor from recursing into the subnodes of a visited node. Consider adding a call ``self.generic_visit(node)`` at the end of the function.
Expand Down
4 changes: 3 additions & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import math
import re
import sys
from collections import namedtuple
from contextlib import suppress
from functools import lru_cache, partial
Expand Down Expand Up @@ -980,7 +981,8 @@ def check_for_b025(self, node):

def check_for_b905(self, node):
if (
isinstance(node.func, ast.Name)
sys.version_info >= (3, 10)
and isinstance(node.func, ast.Name)
and node.func.id == "zip"
and not any(kw.arg == "strict" for kw in node.keywords)
):
Expand Down
File renamed without changes.
29 changes: 16 additions & 13 deletions tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,20 +494,23 @@ def test_b904(self):
]
self.assertEqual(errors, self.errors(*expected))

@unittest.skipIf(sys.version_info < (3, 10), "requires 3.10+")
def test_b905(self):
filename = Path(__file__).absolute().parent / "b905_py310.py"
bbc = BugBearChecker(filename=str(filename))
errors = list(bbc.run())
expected = [
B905(1, 0),
B905(2, 0),
B905(3, 0),
B905(4, 0),
B905(4, 15),
B905(5, 4),
B905(6, 0),
]
filename = Path(__file__).absolute().parent / "b905.py"
bbc = BugBearChecker(filename=str(filename))
errors = list(bbc.run())
expected = (
[
B905(1, 0),
B905(2, 0),
B905(3, 0),
B905(4, 0),
B905(4, 15),
B905(5, 4),
B905(6, 0),
]
if sys.version_info >= (3, 10)
else []
)
self.assertEqual(errors, self.errors(*expected))

def test_b906(self):
Expand Down

0 comments on commit 4d8d807

Please sign in to comment.