Skip to content

[Autofix error] UP018 autofix fails when str() call is inside f-string: f"{str()}" #4322

@konstin

Description

@konstin

In ruff 99a755f, the following snippet causes the autofix UP018 from the pyupgrade rules to introduce a syntax error:

f"{str()}"
$ ./ruff --no-cache --select UP018 --fix code.py

error: Autofix introduced a syntax error. Reverting all changes.

This indicates a bug in `ruff`. If you could open an issue at:

    https://github.com/charliermarsh/ruff/issues/new?title=%5BAutofix%20error%5D

...quoting the contents of `code.py`, the rule codes UP018, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

code.py:1:4: UP018 Unnecessary call to `str`
Found 1 error.

This was originally discovered in https://github.com/Scille/parsec-cloud/blob/114c80f2349e555ebac1aef132ac9289de7c8dff/misc/releaser.py#L120

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixesRelated 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