-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Failure to format when double-quotes are in an f-string's code block #4351
Comments
This is fixed in Black 24.4.1. |
Thanks for the heads up! I verified this on my machine. I was relying on the instructions:
to get the latest version, and so I continued on with the bug report since it also has an issue. Does that mean that the latest version has a new, different issue? As mentioned in the bug report, the online formatter returns:
|
Good point that maybe we should stop recommending the online formatter. The online formatter doesn't work here because this syntax is new in Python 3.12, and the formatter apparently runs an older version of Black at runtime. Black's own parser is independent of the Python version, but the AST safety check relies on Python's builtin parser. |
Ahh, gotcha. Yea, I apologize for not doing due diligence and running I am somewhat new to the Python ecosystem, and I immediately upgraded the existing codebase I inherited to Python 3.12, so I'm often unaware of the subtle changes that have happened across the versions. |
Great! Thanks! |
Does the VSCode plugin depend on the installed Python version? My VSCode plugin is still on |
It says in the extension page that:
For my personal use, I use the VS Code setting (which is documented in the above link):
That's because I use Poetry for all of my Python development, I configure Poetry to place the virtual environment ( |
Describe the bug
See the code example.
To Reproduce
The resulting error is:
It fails at the first
"
inside the f-string's code block when indexing the dictionary.As a note, the online formatter actually gives a different error, which makes even less sense:
Expected behavior
This is valid syntax. For example, in a Python REPL:
I expect no errors.
Environment
24.4.0
Additional context
There is a workaround, and that is to replace the dictionary indexing double-quotes with single-quotes. Black is able to format this equivalent code:
Also, regarding the online formatter, when I make this adjustment, it is also able to complete its formatting of this code. So it has an additional issue complaining about an unmatched
[
, which is obviously not the case if the switch from"asdf"
to'asdf'
fixes that error.The text was updated successfully, but these errors were encountered: