ruff
728609a0 - [`ruff`] Suppress diagnostic for invalid f-strings before Python 3.12 (`RUF027`) (#23480)

Commit
2 days ago
[`ruff`] Suppress diagnostic for invalid f-strings before Python 3.12 (`RUF027`) (#23480) ## Summary Fixes #23460. Comments inside f-string interpolations (`#`) are only valid in Python 3.12+ ([PEP 701](https://peps.python.org/pep-0701/)). RUF027 was not checking for this, so it could produce invalid f-strings when the interpolation text contained a `#` and `target-version` was below 3.12. ## Fix Extended the existing `target_version < PY312` backslash check to also cover comments: ```rust if target_version < PythonVersion::PY312 && (interpolation_text.contains('\\') || interpolation_text.contains('#')) { return false; } ``` ## Test Plan Added a test fixture with a comment inside an f-string interpolation (`{x # }`). The existing `assert_diagnostics_diff!` test for PY311 vs PY312 will capture the new suppression. ## Reproducer (from #23460) ```python x = "!" print("""{x # } }""") ``` On `--target-version py311`, this should not trigger RUF027 since the resulting f-string would contain a comment in the interpolation, which is a syntax error before Python 3.12. --------- Co-authored-by: User <user@example.com> Co-authored-by: stakeswky <stakeswky@users.noreply.github.com>
Author
Parents
Loading