We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Describe the bug
Black unexpectedly can't parse complex conditional list comprehensions inside of f-strings. Check out the example below.
To Reproduce
For example, take this code:
subdirs = ["foodir", "bardir", "tests"] subdir_options = f" ({", ".join([dir for dir in subdirs if dir != "tests"])})" if subdirs else ""
And run it with these arguments:
$ black file.py --target-version py312
The resulting error is:
Cannot parse: 128:71: subdir_options = f" ({", ".join([dir for dir in subdirs if dir != "tests"])})" if subdirs else ""
Expected behavior
Black should parse this valid python.
Environment
This does work if I change the f-string to use single quotes!:
subdir_options = f' ({", ".join([dir for dir in subdirs if dir != "tests"])})' if subdirs else ""
Black succeeds in formatting it to:
subdir_options = ( f' ({", ".join([dir for dir in subdirs if dir != "tests"])})' if subdirs else "" )
The text was updated successfully, but these errors were encountered:
Duplicate of #3746. (Note this syntax only works in Python 3.12 and higher.)
Sorry, something went wrong.
Thanks! I found a workaround, see above.
No branches or pull requests
Describe the bug
Black unexpectedly can't parse complex conditional list comprehensions inside of f-strings. Check out the example below.
To Reproduce
For example, take this code:
And run it with these arguments:
The resulting error is:
Expected behavior
Black should parse this valid python.
Environment
Workaround
This does work if I change the f-string to use single quotes!:
Black succeeds in formatting it to:
The text was updated successfully, but these errors were encountered: