Skip to content

SIM222: false positive on format strings #9479

@reitzig

Description

@reitzig

Consider this script:

repro.py

def foo(a: str, b: str) -> None:
    print(f"{a}{b}" or "bar")


if __name__ == "__main__":
    foo("Hello ", "World")
    foo("", "")

When run, it prints:

❯ python repro.py
Hello World
bar

So apparently, f"{a}{b}" is not a truthy constant! And yet:

❯ ruff --version
ruff 0.1.11
❯ ruff check --isolated --select=SIM repro.py
repro.py:2:11: SIM222 Use `f"{a}{b}"` instead of `f"{a}{b}" or ...`
Found 1 error.
No fixes available (1 hidden fix can be enabled with the `--unsafe-fixes` option).

FWIW, SonarLint's python:S5797 triggers as well.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions