Skip to content

Q000 fixer does not remove obsolete backslash-escape inside string after changing quotes #8617

@ThiefMaster

Description

@ThiefMaster

ruff.toml:

select = ['Q']

[flake8-quotes]
inline-quotes = 'single'
multiline-quotes = 'single'
docstring-quotes = 'double'
avoid-escape = true

Code:

a = "hello\"world"

ruff output:

[adrian@claptrap:/tmp/rufftest]> ~/dev/ruff/target/release/ruff check --no-cache test.py
test.py:1:5: Q000 [*] Double quotes found but single quotes preferred
Found 1 error.
[*] 1 fixable with the `--fix` option.

And after running with --fix added:

a = 'hello\"world'

While not invalid, this is ugly - in particular since avoid-escape is enabled. It should have been this:

a = 'hello"world'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwishNot on the current roadmap; maybe in the future

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions