Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examine kw-only args for mutable defaults #49

Merged
merged 1 commit into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bugbear.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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