Skip to content

B006 (mutable-argument-default) no longer offers autofix even with --unsafe-fixes #8104

@cjolowicz

Description

@cjolowicz

Hello 👋

B006 (mutable-argument-default) no longer offers an autofix even when --unsafe-fixes is passed.

Use the example from ruff rule B006 to reproduce this:

# /tmp/bad.py
def add_to_list(item, some_list=[]):
    some_list.append(item)
    return some_list

At HEAD (df807ff) and v0.1.1:

❯ cargo run -p ruff_cli -- check --select B --unsafe-fixes /tmp/bad.py --no-cache
/tmp/bad.py:1:33: B006 Do not use mutable data structures for argument defaults
Found 1 error.

I've bisected this to 22e1874, but that may only be where the issue was surfaced in the CLI.

The output is slightly different in that commit, there's an additional line:

/tmp/bad.py:1:33: B006 Do not use mutable data structures for argument defaults
Found 1 error.
[*] 0 fixable with the --fix option.

If I omit --unsafe-fixes there's a hint about a hidden fix:

❯ cargo run -p ruff_cli -- check --select B /tmp/bad2.py --no-cache
/tmp/bad.py:1:33: B006 Do not use mutable data structures for argument defaults
Found 1 error.
1 hidden fix can be enabled with the `--unsafe-fixes` option.

(I don't see this hint in 0.1.1 or HEAD, but I haven't bisected where it went away.)

In the parent of the bisected commit and in v0.0.292, I get the expected output:

/tmp/bad.py:1:33: B006 [*] Do not use mutable data structures for argument defaults
Found 1 error.
[*] 1 potentially fixable with the --fix option.

(I noticed after the fact that I ran Ruff from its repository which has Ruff config in pyproject.toml, so that could have skewed results a little. But the repro should still be valid.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixesRelated to suggested fixes for violations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions