Skip to content

Commit

Permalink
Exclude types.MappingProxyType() from B008 (#144)
Browse files Browse the repository at this point in the history
* Exclude types.MappingProxyType() from B008

* Update README.rst
  • Loading branch information
hukkinj1 authored Nov 13, 2020
1 parent d1a9ec7 commit 7b73c9d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Next version
~~~~~~~~~~~~

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

20.1.4
~~~~~~
Expand Down
7 changes: 6 additions & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,12 @@ def visit(self, node):
"use that variable as a default value."
)
)
B008.immutable_calls = {"tuple", "frozenset"}
B008.immutable_calls = {
"tuple",
"frozenset",
"types.MappingProxyType",
"MappingProxyType",
}
B009 = Error(
message=(
"B009 Do not call getattr with a constant attribute value, "
Expand Down
12 changes: 12 additions & 0 deletions tests/b006_b008.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import collections
import logging
import time
import types
from types import MappingProxyType


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


def frozenset_also_okay(value=frozenset()):
pass


def mappingproxytype_okay(
value=MappingProxyType({}), value2=types.MappingProxyType({})
):
pass


def this_is_wrong(value=[1, 2, 3]):
...

Expand Down
14 changes: 7 additions & 7 deletions tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def test_b006_b008(self):
self.assertEqual(
errors,
self.errors(
B006(14, 24),
B006(18, 29),
B006(22, 19),
B006(26, 19),
B006(30, 31),
B008(39, 38),
B006(55, 32),
B006(26, 24),
B006(30, 29),
B006(34, 19),
B006(38, 19),
B006(42, 31),
B008(51, 38),
B006(67, 32),
),
)

Expand Down

0 comments on commit 7b73c9d

Please sign in to comment.