Skip to content

Commit 7b73c9d

Browse files
authored
Exclude types.MappingProxyType() from B008 (#144)
* Exclude types.MappingProxyType() from B008 * Update README.rst
1 parent d1a9ec7 commit 7b73c9d

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ Next version
253253
~~~~~~~~~~~~
254254

255255
* Introduce B016 to check for raising a literal. (#141)
256+
* Exclude types.MappingProxyType() from B008. (#144)
256257

257258
20.1.4
258259
~~~~~~

bugbear.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,12 @@ def visit(self, node):
632632
"use that variable as a default value."
633633
)
634634
)
635-
B008.immutable_calls = {"tuple", "frozenset"}
635+
B008.immutable_calls = {
636+
"tuple",
637+
"frozenset",
638+
"types.MappingProxyType",
639+
"MappingProxyType",
640+
}
636641
B009 = Error(
637642
message=(
638643
"B009 Do not call getattr with a constant attribute value, "

tests/b006_b008.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import collections
22
import logging
33
import time
4+
import types
5+
from types import MappingProxyType
46

57

68
def this_is_okay(value=(1, 2, 3)):
@@ -11,6 +13,16 @@ def and_this_also(value=tuple()):
1113
pass
1214

1315

16+
def frozenset_also_okay(value=frozenset()):
17+
pass
18+
19+
20+
def mappingproxytype_okay(
21+
value=MappingProxyType({}), value2=types.MappingProxyType({})
22+
):
23+
pass
24+
25+
1426
def this_is_wrong(value=[1, 2, 3]):
1527
...
1628

tests/test_bugbear.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ def test_b006_b008(self):
9797
self.assertEqual(
9898
errors,
9999
self.errors(
100-
B006(14, 24),
101-
B006(18, 29),
102-
B006(22, 19),
103-
B006(26, 19),
104-
B006(30, 31),
105-
B008(39, 38),
106-
B006(55, 32),
100+
B006(26, 24),
101+
B006(30, 29),
102+
B006(34, 19),
103+
B006(38, 19),
104+
B006(42, 31),
105+
B008(51, 38),
106+
B006(67, 32),
107107
),
108108
)
109109

0 commit comments

Comments
 (0)