Repository: PyCQA/flake8-bugbear

Issue:
B008: Whitelist operator.{attrgetter,itemgetter,methodcaller} default args
Calling those functions in default args is perfectly fine and *not* calling them would most likely be a bug.

Discussion:

Patch:
diff --git a/bugbear.py b/bugbear.py
index b881b8b..40708b9 100644
--- a/bugbear.py
+++ b/bugbear.py
@@ -694,6 +694,13 @@ B008.immutable_calls = {
     "frozenset",
     "types.MappingProxyType",
     "MappingProxyType",
+    "re.compile",
+    "operator.attrgetter",
+    "operator.itemgetter",
+    "operator.methodcaller",
+    "attrgetter",
+    "itemgetter",
+    "methodcaller",
 }
 B009 = Error(
     message=(


Test patch:
diff --git a/tests/b006_b008.py b/tests/b006_b008.py
index e60e968..40bf797 100644
--- a/tests/b006_b008.py
+++ b/tests/b006_b008.py
@@ -1,7 +1,10 @@
 import collections
 import logging
+import operator
+import re
 import time
 import types
+from operator import attrgetter, itemgetter, methodcaller
 from types import MappingProxyType
 
 
@@ -98,3 +101,21 @@ def float_int_is_wrong(value=float(3)):
 
 def float_str_not_inf_or_nan_is_wrong(value=float("3.14")):
     pass
+
+
+def re_compile_ok(value=re.compile("foo")):
+    pass
+
+
+def operators_ok(
+    v=operator.attrgetter("foo"),
+    v2=operator.itemgetter("foo"),
+    v3=operator.methodcaller("foo"),
+):
+    pass
+
+
+def operators_ok_unqualified(
+    v=attrgetter("foo"), v2=itemgetter("foo"), v3=methodcaller("foo")
+):
+    pass
diff --git a/tests/test_bugbear.py b/tests/test_bugbear.py
index c6e31bb..428d313 100644
--- a/tests/test_bugbear.py
+++ b/tests/test_bugbear.py
@@ -99,15 +99,15 @@ class BugbearTestCase(unittest.TestCase):
         self.assertEqual(
             errors,
             self.errors(
-                B006(26, 24),
-                B006(30, 29),
-                B006(34, 19),
-                B006(38, 19),
-                B006(42, 31),
-                B008(51, 38),
-                B006(67, 32),
-                B008(95, 29),
-                B008(99, 44),
+                B006(29, 24),
+                B006(33, 29),
+                B006(37, 19),
+                B006(41, 19),
+                B006(45, 31),
+                B008(54, 38),
+                B006(70, 32),
+                B008(98, 29),
+                B008(102, 44),
             ),
         )