Skip to content

[Autofix error] C408 - unnecessary-collection-call - syntax error when fixing within f-string #4249

@Hnasar

Description

@Hnasar

Presumably replacing dict() with {} gets confused when inside an f-string when it comes to using " vs ' (or maybe it's the nested {)

# test.py
f"{dict(x='y')}"  # should turn into f"{{'x': 'y'}}"
$ ruff --select=C408 test.py  --fix

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 `test.py`, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

test.py:1:4: C408 Unnecessary `dict` call (rewrite as a literal)

Using ruff 0.0.264

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions