Skip to content

[Autofix error] PIE810 autofix fails when inside f-string: f"{key.startswith('a') or key.startswith('b')}" #4323

@konstin

Description

@konstin

In ruff 99a755f, the following snippet causes the autofix PIE810 from the flake8-pie rules to introduce a syntax error:

f"{key.startswith('a') or key.startswith('b')}"
$ ./ruff --no-cache --select PIE810 --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 PIE810, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

code.py:1:4: PIE810 Call `startswith` once with a `tuple`
Found 1 error.

This was originally discovered in https://github.com/Mojino01/hugging_face/blob/3dae0d7b4fb8d7e9383b893e4e1799191bb2ab7b/src/transformers/models/luke/convert_luke_original_pytorch_checkpoint_to_pytorch.py#L81

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