Skip to content

Commit

Permalink
Examine kw-only args for mutable defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
gaul committed Jul 19, 2018
1 parent 6bf40ea commit 1ab3281
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def check_for_b005(self, node):
)

def check_for_b006(self, node):
for default in node.args.defaults:
for default in node.args.defaults + node.args.kw_defaults:
if isinstance(default, B006.mutable_literals):
self.errors.append(
B006(default.lineno, default.col_offset)
Expand Down
6 changes: 6 additions & 0 deletions tests/b006_b008.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ def in_fact_all_calls_are_wrong(value=time.time()):
def do_this_instead_of_calls_in_defaults(logger=LOGGER):
# That makes it more obvious that this one value is reused.
...

def kwonlyargs_immutable(*, value=()):
...

def kwonlyargs_mutable(*, value=[]):
...
2 changes: 1 addition & 1 deletion tests/test_bugbear.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_b006_b008(self):
self.assertEqual(
errors,
self.errors(B006(10, 24), B006(14, 29), B006(18, 19), B006(22, 19),
B006(25, 31), B008(32, 38)),
B006(25, 31), B008(32, 38), B006(43, 32)),
)

def test_b007(self):
Expand Down

0 comments on commit 1ab3281

Please sign in to comment.