Skip to content

Commit

Permalink
B008: Whitelist more immutable function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster committed Jun 19, 2021
1 parent 63239e0 commit faf7bb5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
7 changes: 7 additions & 0 deletions bugbear.py
Expand Up @@ -694,6 +694,13 @@ def visit(self, node):
"frozenset",
"types.MappingProxyType",
"MappingProxyType",
"re.compile",
"operator.attrgetter",
"operator.itemgetter",
"operator.methodcaller",
"attrgetter",
"itemgetter",
"methodcaller",
}
B009 = Error(
message=(
Expand Down
23 changes: 23 additions & 0 deletions 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


Expand Down Expand Up @@ -98,3 +101,23 @@ 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
18 changes: 9 additions & 9 deletions tests/test_bugbear.py
Expand Up @@ -99,15 +99,15 @@ def test_b006_b008(self):
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),
),
)

Expand Down

0 comments on commit faf7bb5

Please sign in to comment.