Skip to content

Commit f6e9a57

Browse files
committed
Examine kw-only args for mutable defaults
1 parent b8b4df4 commit f6e9a57

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

bugbear.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def check_for_b005(self, node):
239239
self.errors.append(B005(node.lineno, node.col_offset))
240240

241241
def check_for_b006(self, node):
242-
for default in node.args.defaults:
242+
for default in node.args.defaults + node.args.kw_defaults:
243243
if isinstance(default, B006.mutable_literals):
244244
self.errors.append(B006(default.lineno, default.col_offset))
245245
elif isinstance(default, ast.Call):

tests/b006_b008.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@ def in_fact_all_calls_are_wrong(value=time.time()):
4242
def do_this_instead_of_calls_in_defaults(logger=LOGGER):
4343
# That makes it more obvious that this one value is reused.
4444
...
45+
46+
def kwonlyargs_immutable(*, value=()):
47+
...
48+
49+
def kwonlyargs_mutable(*, value=[]):
50+
...

tests/test_bugbear.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def test_b006_b008(self):
8484
B006(22, 19),
8585
B006(26, 31),
8686
B008(35, 38),
87+
B006(49, 32),
8788
),
8889
)
8990

0 commit comments

Comments
 (0)