-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
I'm maintaining a codebase with multiple release branches targeting different Python versions by release. The latest one uses Python 3.12 while prior versions use Python 3.10 or 3.11.
The recent update of Ruff has introduced Python 3.12 f-string support and the Ruff v0.4 formatter replaces all single-quotes in placeholders to double-quotes.
Example:
f"a value from dict: {data['key']}" (the previous way to write string literals in f-string placeholdrs)
→
f"a value from dict: {data["key"]}" (allowed in Python 3.12 but a syntax error in Python 3.11 or older)
The problem is that when I backport this line to a release branch targeting Python 3.11 or older (but using the same Ruff version), Ruff silently ignores the broken syntax. It does not auto-convert the existing codes in Python 3.11, but also does not give errors about the backported codes. Linting will pass, but it will fail when someone executes/imports the code.
In contrast, Black (24.4) loudly fails because the Python parser reports a syntax error.
There could be the following options to resolve the issue:
- Let Ruff 0.4 targeting Python 3.11 or older report the syntax error loudly, just like Black.
- Let Ruff 0.4 targeting Python 3.11 or older auto-convert the double-quotes in f-string placeholders back to single-quotes (or vice-versa depending on the quote style).
- Add an option to keep the single-quotes in f-string placholders intact in Python 3.12 or later.