[pylint] Avoid syntax errors in invalid character replacements in f-strings before Python 3.12 (PLE2510, PLE2512, PLE2513, PLE2514, PLE2515)#25544
Merged
Conversation
ntBre
reviewed
Jun 2, 2026
| stylist, | ||
| source_type, | ||
| source_kind.as_ipy_notebook().map(Notebook::cell_offsets), | ||
| target_version.linter_version(), |
Contributor
There was a problem hiding this comment.
We shouldn't need to pass this separately. We can retrieve the version from the context inside of check_tokens.
| if !token.unwrap_string_flags().is_raw_string() && !is_escaped { | ||
| if !token.unwrap_string_flags().is_raw_string() | ||
| && !is_escaped | ||
| && !(target_version < PythonVersion::PY312 && inside_interpolation) |
Contributor
There was a problem hiding this comment.
I think we should use target_version.supports_pep_701() instead of a direct comparison to PY312.
Contributor
There was a problem hiding this comment.
Should we add any of the other test cases from https://github.com/astral-sh/ruff/pull/23910/changes#diff-233fb41e62597c60b28d2c5a042798417a33955c75feeb9b23e129809767960c?
|
Contributor
Author
|
Thanks, pushed
Local checks now pass:
|
pylint] Avoid syntax errors in invalid character replacements in f-strings before Python 3.12 (PLE2510, PLE2512, PLE2513, PLE2514, PLE2515)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #18816.
When a raw control character appears inside an f-string replacement field or format spec, replacing it with an escape sequence can introduce invalid pre-3.12 syntax. This keeps the diagnostic, but suppresses the fix for interpolated f-string/t-string elements when the target version is older than Python 3.12. Literal f-string text and Python 3.12+ targets keep the existing fix behavior.
Test plan
cargo test -p ruff_linter --features test-rules invalidcharactercargo test -p ruff_linter --features test-rules rules::pylint::tests::invalid_characters_pre_py312cargo fmt --checkgit diff --check