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 b8b4df4 commit f6e9a57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bugbear.py
Expand Up @@ -239,7 +239,7 @@ def check_for_b005(self, node):
self.errors.append(B005(node.lineno, node.col_offset))

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))
elif isinstance(default, ast.Call):
Expand Down
6 changes: 6 additions & 0 deletions tests/b006_b008.py
Expand Up @@ -42,3 +42,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=[]):
...
1 change: 1 addition & 0 deletions tests/test_bugbear.py
Expand Up @@ -84,6 +84,7 @@ def test_b006_b008(self):
B006(22, 19),
B006(26, 31),
B008(35, 38),
B006(49, 32),
),
)

Expand Down

0 comments on commit f6e9a57

Please sign in to comment.