Skip to content
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

black having trouble parsing if statements within fstring #4200

Closed
notsweting opened this issue Jan 31, 2024 · 1 comment
Closed

black having trouble parsing if statements within fstring #4200

notsweting opened this issue Jan 31, 2024 · 1 comment
Labels
T: bug Something isn't working

Comments

@notsweting
Copy link

Describe the bug

Black cannot parse fstrings with one line if statements

To Reproduce

For example, take this code:

a = f'{'1' if 1 else '2'}'

And run it with these arguments:

$ black file.py --target-version py39

The resulting error is:

error: cannot format cogs\black.py: Cannot parse: 4:11: a = f'{'1' if 1 else '2'}'

Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

A "cannot parse" error does not occur and the formatter is able to continue on parsing through the rest of the file.

Environment

  • Black's version: 24.1.1
  • OS and Python version: Windows/Python 3.12.1
@notsweting notsweting added the T: bug Something isn't working label Jan 31, 2024
@hauntsaninja
Copy link
Collaborator

Duplicate of #3746

@hauntsaninja hauntsaninja marked this as a duplicate of #3746 Jan 31, 2024
@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants