-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
F541: Invalid replacement with string concatenation #4827
Comments
Should we automatically fix this case as Since this wasn't apparent to me at first, note that F541 is for f-strings with missing placeholders so if the second string has placeholders i.e. |
Yes, I suspect this is an issue with how strings are formatted -- not just for this case. However, this particular scenario is just very likely for a fuzzer to generate, where other string issues may not be so trivial to trigger. |
We ran into something like this before, in the rule that transforms from strings to f-strings ( // If necessary, add a space between any leading keyword (`return`, `yield`, `assert`, etc.)
// and the string. For example, `return"foo"` is valid, but `returnf"foo"` is not.
let existing = checker.locator.slice(TextRange::up_to(expr.start()));
if existing
.chars()
.last()
.map_or(false, |char| char.is_ascii_alphabetic())
{
contents.insert(0, ' ');
} |
Python allows for string concatenation by placing two strings one after another:
It also permits a string followed by a f-string:
Even those immediately concatenated:
However, there is a niche corner case which causes Ruff to generate invalid syntax: if the first string is empty, followed by an f-string, it will incorrectly generate a triple-quote:
The reproducing example for this is:
Which Ruff corrects to:
Which is invalid syntax. It's worth noting that I don't think any linter currently supports this!
Discovered by #4822.
The text was updated successfully, but these errors were encountered: