Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B008: Whitelist additional immutable function calls #173

Merged
merged 1 commit into from Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
21 changes: 21 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,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
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