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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black cannot parse valid code #4282

Closed
CanePlayz opened this issue Mar 18, 2024 · 2 comments
Closed

Black cannot parse valid code #4282

CanePlayz opened this issue Mar 18, 2024 · 2 comments
Labels
T: bug Something isn't working

Comments

@CanePlayz
Copy link

Describe the bug

Black hits me with this error when trying to format something

error: cannot format ...\test.ipynb: Cannot parse: 4:31: plt.savefig(f"output/_{config["year"].replace("/", "_")}.png", bbox_inches="tight")

Oh no! 馃挜 馃挃 馃挜
1 file failed to reformat.

To Reproduce

Take the code below and try to format it from the command line

For example, take this code:

import matplotlib.pyplot as plt

config = {"year": "2024"}
plt.savefig(f"output/_{config["year"].replace("/", "_")}.png", bbox_inches="tight")

And run it with these arguments:

$ black file.ipynb

Expected behavior

Parse the code fine as it is valid Python code

Environment

  • Black's version: 24.3.0
  • OS and Python version: Windows 11, Python 3.12.2

Additional context

@CanePlayz CanePlayz added the T: bug Something isn't working label Mar 18, 2024
@AlexWaygood
Copy link
Contributor

Hi! This issue is a duplicate of #3746. Note that Python will actually fail to parse your code unless you're using Python 3.12+; this syntax is a pretty new feature :-)

@CanePlayz
Copy link
Author

@AlexWaygood Ah, I didn't see that it was related to that at first, thanks! :)

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