Repository: PyCQA/flake8-bugbear (language: python)

Issue:
[pre-commit.ci] pre-commit autoupdate
<!--pre-commit.ci start-->
updates:
- [github.com/psf/black: 23.7.0 → 23.9.1](https://github.com/psf/black/compare/23.7.0...23.9.1)
<!--pre-commit.ci end-->


Discussion / hints:
We need to adjust a bunch of hardcoded line numbers in the tests...
I'm not a fan of this change :( I need to go read why we (black) did it. I'm tempted to turn off the auto formatting here like I did for bandersnatch ...

Fix patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index c17b158..9d6d121 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -8,7 +8,7 @@ repos:
       - id: isort
 
   - repo: https://github.com/psf/black
-    rev: 23.7.0
+    rev: 23.9.1
     hooks:
       - id: black
         args:


Test patch:
diff --git a/tests/b006_b008.py b/tests/b006_b008.py
index c5411c6..4a4c302 100644
--- a/tests/b006_b008.py
+++ b/tests/b006_b008.py
@@ -12,8 +12,7 @@
 
 # B006
 # Allow immutable literals/calls/comprehensions
-def this_is_okay(value=(1, 2, 3)):
-    ...
+def this_is_okay(value=(1, 2, 3)): ...
 
 
 async def and_this_also(value=tuple()):
@@ -50,35 +49,28 @@ def operators_ok_unqualified(
     pass
 
 
-def kwonlyargs_immutable(*, value=()):
-    ...
+def kwonlyargs_immutable(*, value=()): ...
 
 
 # Flag mutable literals/comprehensions
 
 
-def this_is_wrong(value=[1, 2, 3]):
-    ...
+def this_is_wrong(value=[1, 2, 3]): ...
 
 
-def this_is_also_wrong(value={}):
-    ...
+def this_is_also_wrong(value={}): ...
 
 
-def and_this(value=set()):
-    ...
+def and_this(value=set()): ...
 
 
-def this_too(value=collections.OrderedDict()):
-    ...
+def this_too(value=collections.OrderedDict()): ...
 
 
-async def async_this_too(value=collections.defaultdict()):
-    ...
+async def async_this_too(value=collections.defaultdict()): ...
 
 
-def dont_forget_me(value=collections.deque()):
-    ...
+def dont_forget_me(value=collections.deque()): ...
 
 
 # N.B. we're also flagging the function call in the comprehension
@@ -94,8 +86,7 @@ def set_comprehension_also_not_okay(default={i**2 for i in range(3)}):
     pass
 
 
-def kwonlyargs_mutable(*, value=[]):
-    ...
+def kwonlyargs_mutable(*, value=[]): ...
 
 
 # Recommended approach for mutable defaults
@@ -106,16 +97,14 @@ def do_this_instead(value=None):
 
 # B008
 # Flag function calls as default args (including if they are part of a sub-expression)
-def in_fact_all_calls_are_wrong(value=time.time()):
-    ...
+def in_fact_all_calls_are_wrong(value=time.time()): ...
 
 
 def f(when=dt.datetime.now() + dt.timedelta(days=7)):
     pass
 
 
-def can_even_catch_lambdas(a=(lambda x: x)()):
-    ...
+def can_even_catch_lambdas(a=(lambda x: x)()): ...
 
 
 # Recommended approach for function calls as default args
diff --git a/tests/b008_extended.py b/tests/b008_extended.py
index 3d0fe78..484f68d 100644
--- a/tests/b008_extended.py
+++ b/tests/b008_extended.py
@@ -4,13 +4,10 @@
 from fastapi import Query
 
 
-def this_is_okay_extended(db=fastapi.Depends(get_db)):
-    ...
+def this_is_okay_extended(db=fastapi.Depends(get_db)): ...
 
 
-def this_is_okay_extended_second(data: List[str] = fastapi.Query(None)):
-    ...
+def this_is_okay_extended_second(data: List[str] = fastapi.Query(None)): ...
 
 
-def this_is_not_okay_relative_import_not_listed(data: List[str] = Query(None)):
-    ...
+def this_is_not_okay_relative_import_not_listed(data: List[str] = Query(None)): ...
diff --git a/tests/b019.py b/tests/b019.py
index b074df1..3a1d01e 100644
--- a/tests/b019.py
+++ b/tests/b019.py
@@ -6,98 +6,77 @@
 from functools import cache, cached_property, lru_cache
 
 
-def some_other_cache():
-    ...
+def some_other_cache(): ...
 
 
 class Foo:
     def __init__(self, x):
         self.x = x
 
-    def compute_method(self, y):
-        ...
+    def compute_method(self, y): ...
 
     @some_other_cache
-    def user_cached_method(self, y):
-        ...
+    def user_cached_method(self, y): ...
 
     @classmethod
     @functools.cache
-    def cached_classmethod(cls, y):
-        ...
+    def cached_classmethod(cls, y): ...
 
     @classmethod
     @cache
-    def other_cached_classmethod(cls, y):
-        ...
+    def other_cached_classmethod(cls, y): ...
 
     @classmethod
     @functools.lru_cache
-    def lru_cached_classmethod(cls, y):
-        ...
+    def lru_cached_classmethod(cls, y): ...
 
     @classmethod
     @lru_cache
-    def other_lru_cached_classmethod(cls, y):
-        ...
+    def other_lru_cached_classmethod(cls, y): ...
 
     @staticmethod
     @functools.cache
-    def cached_staticmethod(y):
-        ...
+    def cached_staticmethod(y): ...
 
     @staticmethod
     @cache
-    def other_cached_staticmethod(y):
-        ...
+    def other_cached_staticmethod(y): ...
 
     @staticmethod
     @functools.lru_cache
-    def lru_cached_staticmethod(y):
-        ...
+    def lru_cached_staticmethod(y): ...
 
     @staticmethod
     @lru_cache
-    def other_lru_cached_staticmethod(y):
-        ...
+    def other_lru_cached_staticmethod(y): ...
 
     @functools.cached_property
-    def some_cached_property(self):
-        ...
+    def some_cached_property(self): ...
 
     @cached_property
-    def some_other_cached_property(self):
-        ...
+    def some_other_cached_property(self): ...
 
     # Remaining methods should emit B019
     @functools.cache
-    def cached_method(self, y):
-        ...
+    def cached_method(self, y): ...
 
     @cache
-    def another_cached_method(self, y):
-        ...
+    def another_cached_method(self, y): ...
 
     @functools.cache()
-    def called_cached_method(self, y):
-        ...
+    def called_cached_method(self, y): ...
 
     @cache()
-    def another_called_cached_method(self, y):
-        ...
+    def another_called_cached_method(self, y): ...
 
     @functools.lru_cache
-    def lru_cached_method(self, y):
-        ...
+    def lru_cached_method(self, y): ...
 
     @lru_cache
-    def another_lru_cached_method(self, y):
-        ...
+    def another_lru_cached_method(self, y): ...
 
     @functools.lru_cache()
-    def called_lru_cached_method(self, y):
-        ...
+    def called_lru_cached_method(self, y): ...
 
     @lru_cache()
-    def another_called_lru_cached_method(self, y):
-        ...
+    def another_called_lru_cached_method(self, y): ...
diff --git a/tests/b027.py b/tests/b027.py
index ef8e9a2..218184b 100644
--- a/tests/b027.py
+++ b/tests/b027.py
@@ -32,16 +32,14 @@ def empty_5(self):  # error
         ...
 
     @abstractmethod
-    def abstract_1(self):
-        ...
+    def abstract_1(self): ...
 
     @abstractmethod
     def abstract_2(self):
         pass
 
     @abc.abstractmethod
-    def abstract_3(self):
-        ...
+    def abstract_3(self): ...
 
     def body_1(self):
         print("foo")
@@ -69,21 +67,16 @@ def empty_2(self):  # safe
 
 class AstractClass(ABC):
     @overload
-    def empty_1(self, foo: str):
-        ...
+    def empty_1(self, foo: str): ...
 
     @typing.overload
-    def empty_1(self, foo: int):
-        ...
+    def empty_1(self, foo: int): ...
 
     @t.overload
-    def empty_1(self, foo: list):
-        ...
+    def empty_1(self, foo: list): ...
 
     @anything.overload
-    def empty_1(self, foo: float):
-        ...
+    def empty_1(self, foo: float): ...
 
     @abstractmethod
-    def empty_1(self, foo: Union[str, int, list, float]):
-        ...
+    def empty_1(self, foo: Union[str, int, list, float]): ...
diff --git a/tests/b902.py b/tests/b902.py
index f955d78..f48b09f 100644
--- a/tests/b902.py
+++ b/tests/b902.py
@@ -1,63 +1,47 @@
-def not_a_method(arg1):
-    ...
+def not_a_method(arg1): ...
 
 
 class NoWarnings:
     def __init__(self):
-        def not_a_method_either(arg1):
-            ...
+        def not_a_method_either(arg1): ...
 
-    def __new__(cls, *args, **kwargs):
-        ...
+    def __new__(cls, *args, **kwargs): ...
 
-    def method(self, arg1, *, yeah):
-        ...
+    def method(self, arg1, *, yeah): ...
 
-    async def async_method(self, arg1, *, yeah):
-        ...
+    async def async_method(self, arg1, *, yeah): ...
 
     @classmethod
-    def someclassmethod(cls, arg1, with_default=None):
-        ...
+    def someclassmethod(cls, arg1, with_default=None): ...
 
     @staticmethod
-    def not_a_problem(arg1):
-        ...
+    def not_a_problem(arg1): ...
 
 
 class Warnings:
-    def __init__(i_am_special):
-        ...
+    def __init__(i_am_special): ...
 
-    def almost_a_class_method(cls, arg1):
-        ...
+    def almost_a_class_method(cls, arg1): ...
 
-    def almost_a_static_method():
-        ...
+    def almost_a_static_method(): ...
 
     @classmethod
-    def wat(self, i_like_confusing_people):
-        ...
+    def wat(self, i_like_confusing_people): ...
 
     def i_am_strange(*args, **kwargs):
         self = args[0]
 
-    def defaults_anyone(self=None):
-        ...
+    def defaults_anyone(self=None): ...
 
-    def invalid_kwargs_only(**kwargs):
-        ...
+    def invalid_kwargs_only(**kwargs): ...
 
-    def invalid_keyword_only(*, self):
-        ...
+    def invalid_keyword_only(*, self): ...
 
-    async def async_invalid_keyword_only(*, self):
-        ...
+    async def async_invalid_keyword_only(*, self): ...
 
 
 class Meta(type):
-    def __init__(cls, name, bases, d):
-        ...
+    def __init__(cls, name, bases, d): ...
 
     @classmethod
     def __prepare__(metacls, name, bases):
@@ -65,16 +49,14 @@ def __prepare__(metacls, name, bases):
 
 
 class OtherMeta(type):
-    def __init__(self, name, bases, d):
-        ...
+    def __init__(self, name, bases, d): ...
 
     @classmethod
     def __prepare__(cls, name, bases):
         return {}
 
     @classmethod
-    def first_arg_mcs_allowed(mcs, value):
-        ...
+    def first_arg_mcs_allowed(mcs, value): ...
 
 
 def type_factory():
@@ -82,21 +64,16 @@ def type_factory():
 
 
 class CrazyBases(Warnings, type_factory(), metaclass=type):
-    def __init__(self):
-        ...
+    def __init__(self): ...
 
 
 class RuntimeError("This is not a base"):
-    def __init__(self):
-        ...
+    def __init__(self): ...
 
 
 class ImplicitClassMethods:
-    def __new__(cls, *args, **kwargs):
-        ...
+    def __new__(cls, *args, **kwargs): ...
 
-    def __init_subclass__(cls, *args, **kwargs):
-        ...
+    def __init_subclass__(cls, *args, **kwargs): ...
 
-    def __class_getitem__(cls, key):
-        ...
+    def __class_getitem__(cls, key): ...
diff --git a/tests/b902_py38.py b/tests/b902_py38.py
index 7a942e8..9d81e15 100644
--- a/tests/b902_py38.py
+++ b/tests/b902_py38.py
@@ -1,63 +1,47 @@
-def not_a_method(arg1, /):
-    ...
+def not_a_method(arg1, /): ...
 
 
 class NoWarnings:
     def __init__(self, /):
-        def not_a_method_either(arg1, /):
-            ...
+        def not_a_method_either(arg1, /): ...
 
-    def __new__(cls, /, *args, **kwargs):
-        ...
+    def __new__(cls, /, *args, **kwargs): ...
 
-    def method(self, arg1, /, *, yeah):
-        ...
+    def method(self, arg1, /, *, yeah): ...
 
-    async def async_method(self, arg1, /, *, yeah):
-        ...
+    async def async_method(self, arg1, /, *, yeah): ...
 
     @classmethod
-    def someclassmethod(cls, arg1, with_default=None, /):
-        ...
+    def someclassmethod(cls, arg1, with_default=None, /): ...
 
     @staticmethod
-    def not_a_problem(arg1, /):
-        ...
+    def not_a_problem(arg1, /): ...
 
 
 class Warnings:
-    def __init__(i_am_special, /):
-        ...
+    def __init__(i_am_special, /): ...
 
-    def almost_a_class_method(cls, arg1, /):
-        ...
+    def almost_a_class_method(cls, arg1, /): ...
 
-    def almost_a_static_method():
-        ...
+    def almost_a_static_method(): ...
 
     @classmethod
-    def wat(self, i_like_confusing_people, /):
-        ...
+    def wat(self, i_like_confusing_people, /): ...
 
     def i_am_strange(*args, **kwargs):
         self = args[0]
 
-    def defaults_anyone(self=None, /):
-        ...
+    def defaults_anyone(self=None, /): ...
 
-    def invalid_kwargs_only(**kwargs):
-        ...
+    def invalid_kwargs_only(**kwargs): ...
 
-    def invalid_keyword_only(*, self):
-        ...
+    def invalid_keyword_only(*, self): ...
 
-    async def async_invalid_keyword_only(*, self):
-        ...
+    async def async_invalid_keyword_only(*, self): ...
 
 
 class Meta(type):
-    def __init__(cls, name, bases, d, /):
-        ...
+    def __init__(cls, name, bases, d, /): ...
 
     @classmethod
     def __prepare__(metacls, name, bases, /):
@@ -65,16 +49,14 @@ def __prepare__(metacls, name, bases, /):
 
 
 class OtherMeta(type):
-    def __init__(self, name, bases, d, /):
-        ...
+    def __init__(self, name, bases, d, /): ...
 
     @classmethod
     def __prepare__(cls, name, bases, /):
         return {}
 
     @classmethod
-    def first_arg_mcs_allowed(mcs, value, /):
-        ...
+    def first_arg_mcs_allowed(mcs, value, /): ...
 
 
 def type_factory():
@@ -82,21 +64,16 @@ def type_factory():
 
 
 class CrazyBases(Warnings, type_factory(), metaclass=type):
-    def __init__(self):
-        ...
+    def __init__(self): ...
 
 
 class RuntimeError("This is not a base"):
-    def __init__(self):
-        ...
+    def __init__(self): ...
 
 
 class ImplicitClassMethods:
-    def __new__(cls, /, *args, **kwargs):
-        ...
+    def __new__(cls, /, *args, **kwargs): ...
 
-    def __init_subclass__(cls, /, *args, **kwargs):
-        ...
+    def __init_subclass__(cls, /, *args, **kwargs): ...
 
-    def __class_getitem__(cls, key, /):
-        ...
+    def __class_getitem__(cls, key, /): ...
diff --git a/tests/b903.py b/tests/b903.py
index ebe3913..78da444 100644
--- a/tests/b903.py
+++ b/tests/b903.py
@@ -3,8 +3,7 @@ def __init__(self, foo, bar):
         self.foo = foo
         self.bar = bar
 
-    def other_function(self):
-        ...
+    def other_function(self): ...
 
 
 class NoWarningsClassAttributes:
diff --git a/tests/b906.py b/tests/b906.py
index 648489c..b96a00e 100644
--- a/tests/b906.py
+++ b/tests/b906.py
@@ -6,8 +6,7 @@
 
 
 # error
-def visit_For():
-    ...
+def visit_For(): ...
 
 
 # has call to visit function
@@ -27,74 +26,58 @@ def foo():
 
 
 # not a valid AST class, no error
-def visit_foo():
-    ...
+def visit_foo(): ...
 
 
 # Break has no subfields to visit, so no error
-def visit_Break():
-    ...
+def visit_Break(): ...
 
 
 # explicitly check `visit` and `generic_visit`
 # doesn't start with _visit, safe
-def visit():
-    ...
+def visit(): ...
 
 
 # doesn't start with _visit, safe
-def generic_visit():
-    ...
+def generic_visit(): ...
 
 
 # check no crash on short name
-def a():
-    ...
+def a(): ...
 
 
-def visit_():
-    ...
+def visit_(): ...
 
 
 # Check exceptions for ast types that only contain ADSL builtin types
 # i.e. don't contain any ast.AST subnodes and therefore don't need a generic_visit
-def visit_alias():
-    ...
+def visit_alias(): ...
 
 
-def visit_Constant():
-    ...
+def visit_Constant(): ...
 
 
-def visit_Global():
-    ...
+def visit_Global(): ...
 
 
-def visit_MatchSingleton():
-    ...
+def visit_MatchSingleton(): ...
 
 
-def visit_MatchStar():
-    ...
+def visit_MatchStar(): ...
 
 
-def visit_Nonlocal():
-    ...
+def visit_Nonlocal(): ...
 
 
-def visit_TypeIgnore():
-    ...
+def visit_TypeIgnore(): ...
 
 
 # These nodes are deprecated, but some codebases may still use them
 # for backwards-compatibility with Python 3.7
-def visit_Bytes():
-    ...
+def visit_Bytes(): ...
 
 
-def visit_Num():
-    ...
+def visit_Num(): ...
 
 
-def visit_Str():
-    ...
+def visit_Str(): ...
diff --git a/tests/test_bugbear.py b/tests/test_bugbear.py
index eb91032..cc93e24 100644
--- a/tests/test_bugbear.py
+++ b/tests/test_bugbear.py
@@ -114,31 +114,31 @@ def test_b006_b008(self):
         self.assertEqual(
             errors,
             self.errors(
-                B006(60, 24),
-                B006(64, 29),
-                B006(68, 19),
-                B006(72, 19),
-                B006(76, 31),
-                B006(80, 25),
-                B006(85, 45),
-                B008(85, 60),
-                B006(89, 45),
-                B008(89, 63),
-                B006(93, 44),
-                B008(93, 59),
-                B006(97, 32),
-                B008(109, 38),
-                B008(113, 11),
-                B008(113, 31),
-                B008(117, 29),
-                B008(160, 29),
-                B008(164, 44),
-                B006(170, 19),
-                B008(170, 20),
-                B008(170, 30),
-                B008(176, 21),
-                B008(181, 18),
-                B008(181, 36),
+                B006(58, 24),
+                B006(61, 29),
+                B006(64, 19),
+                B006(67, 19),
+                B006(70, 31),
+                B006(73, 25),
+                B006(77, 45),
+                B008(77, 60),
+                B006(81, 45),
+                B008(81, 63),
+                B006(85, 44),
+                B008(85, 59),
+                B006(89, 32),
+                B008(100, 38),
+                B008(103, 11),
+                B008(103, 31),
+                B008(107, 29),
+                B008(149, 29),
+                B008(153, 44),
+                B006(159, 19),
+                B008(159, 20),
+                B008(159, 30),
+                B008(165, 21),
+                B008(170, 18),
+                B008(170, 36),
             ),
         )
 
@@ -168,7 +168,7 @@ def test_b008_extended(self):
 
         self.assertEqual(
             errors,
-            self.errors(B008(15, 66)),
+            self.errors(B008(13, 66)),
         )
 
     def test_b009_b010(self):
@@ -296,14 +296,14 @@ def test_b019(self):
         self.assertEqual(
             errors,
             self.errors(
-                B019(73, 5),
-                B019(77, 5),
+                B019(60, 5),
+                B019(63, 5),
+                B019(66, 5),
+                B019(69, 5),
+                B019(72, 5),
+                B019(75, 5),
+                B019(78, 5),
                 B019(81, 5),
-                B019(85, 5),
-                B019(89, 5),
-                B019(93, 5),
-                B019(97, 5),
-                B019(101, 5),
             ),
         )
 
@@ -654,16 +654,16 @@ def test_b902(self):
         self.assertEqual(
             errors,
             self.errors(
-                B902(29, 17, vars=("'i_am_special'", "instance", "self")),
-                B902(32, 30, vars=("'cls'", "instance", "self")),
-                B902(35, 4, vars=("(none)", "instance", "self")),
-                B902(39, 12, vars=("'self'", "class", "cls")),
-                B902(42, 22, vars=("*args", "instance", "self")),
-                B902(48, 30, vars=("**kwargs", "instance", "self")),
-                B902(51, 32, vars=("*, self", "instance", "self")),
-                B902(54, 44, vars=("*, self", "instance", "self")),
-                B902(68, 17, vars=("'self'", "metaclass instance", "cls")),
-                B902(72, 20, vars=("'cls'", "metaclass class", "metacls")),
+                B902(22, 17, vars=("'i_am_special'", "instance", "self")),
+                B902(24, 30, vars=("'cls'", "instance", "self")),
+                B902(26, 4, vars=("(none)", "instance", "self")),
+                B902(29, 12, vars=("'self'", "class", "cls")),
+                B902(31, 22, vars=("*args", "instance", "self")),
+                B902(36, 30, vars=("**kwargs", "instance", "self")),
+                B902(38, 32, vars=("*, self", "instance", "self")),
+                B902(40, 44, vars=("*, self", "instance", "self")),
+                B902(52, 17, vars=("'self'", "metaclass instance", "cls")),
+                B902(55, 20, vars=("'cls'", "metaclass class", "metacls")),
             ),
         )
 
@@ -674,16 +674,16 @@ def test_b902_py38(self):
         self.assertEqual(
             errors,
             self.errors(
-                B902(29, 17, vars=("'i_am_special'", "instance", "self")),
-                B902(32, 30, vars=("'cls'", "instance", "self")),
-                B902(35, 4, vars=("(none)", "instance", "self")),
-                B902(39, 12, vars=("'self'", "class", "cls")),
-                B902(42, 22, vars=("*args", "instance", "self")),
-                B902(48, 30, vars=("**kwargs", "instance", "self")),
-                B902(51, 32, vars=("*, self", "instance", "self")),
-                B902(54, 44, vars=("*, self", "instance", "self")),
-                B902(68, 17, vars=("'self'", "metaclass instance", "cls")),
-                B902(72, 20, vars=("'cls'", "metaclass class", "metacls")),
+                B902(22, 17, vars=("'i_am_special'", "instance", "self")),
+                B902(24, 30, vars=("'cls'", "instance", "self")),
+                B902(26, 4, vars=("(none)", "instance", "self")),
+                B902(29, 12, vars=("'self'", "class", "cls")),
+                B902(31, 22, vars=("*args", "instance", "self")),
+                B902(36, 30, vars=("**kwargs", "instance", "self")),
+                B902(38, 32, vars=("*, self", "instance", "self")),
+                B902(40, 44, vars=("*, self", "instance", "self")),
+                B902(52, 17, vars=("'self'", "metaclass instance", "cls")),
+                B902(55, 20, vars=("'cls'", "metaclass class", "metacls")),
             ),
         )
 
@@ -691,7 +691,7 @@ def test_b903(self):
         filename = Path(__file__).absolute().parent / "b903.py"
         bbc = BugBearChecker(filename=str(filename))
         errors = list(bbc.run())
-        self.assertEqual(errors, self.errors(B903(32, 0), B903(38, 0)))
+        self.assertEqual(errors, self.errors(B903(31, 0), B903(37, 0)))
 
     def test_b904(self):
         filename = Path(__file__).absolute().parent / "b904.py"