Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIM222: false positive on format strings #9479

Closed
reitzig opened this issue Jan 11, 2024 · 1 comment · Fixed by #9484
Closed

SIM222: false positive on format strings #9479

reitzig opened this issue Jan 11, 2024 · 1 comment · Fixed by #9484
Assignees
Labels
bug Something isn't working

Comments

@reitzig
Copy link

reitzig commented Jan 11, 2024

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.

@charliermarsh
Copy link
Member

Thanks, I actually thought we had handling for this, but apparently not :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants