-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 cannot parse previously parseable file in 24.4.1 #4329
Comments
Thanks! cc @tusharsadhwani. |
No no, thank YOU! We love your tool :) (Well, I love it. My team grumbles when they forget to run it and our linting job snarks at them.) |
This seems like the minimal reproduction: f"{1:{f'{2}'}}" |
actually, using same or different quotes gives us two different crash scenarios: f'{1:{f'{2}'}}' If the quotes of the outer and inner fstring are the same, we get a different crash. |
Using the same quotes is a syntax error in Python itself. You terminate the string early. >>> f'{1:{f'{2}'}}'
File "<stdin>", line 1
f'{1:{f'{2}'}}'
^
SyntaxError: f-string: expecting '}' |
@tarper24 it works fine on Python 3.12 onwards. |
@tarper24 not in Python 3.12 any more. That's actually why we made this change; we had to revamp the parser around f-strings to support the new syntax. Unfortunately that caused us to start failing on some f-strings that were already valid. We found a few such cases before release by running Black on various codebases, but unfortunately we missed your case. |
I spent some time on this but couldn't figure out a solution yet. The reproducer gets tokenized like this:
The My current thinking is that the issue is that the |
Commenting out |
Also it's not the FSTRING_MIDDLE that's incorrect, it's the OP just above it, which should be an RBRACE to match the LBRACE. |
The minimised case that breaks when making the bracelev change is: f'{1:{2}d}' |
What is the difference between OP and LBRACE/RBRACE here? I noticed the variation but it wasn't clear to me which one is correct. |
In the original impl it's very blurry what to use, but I went with yielding LBRACE whenever we go from collecting FSTRING_MIDDLE tokens to parsing python expressions again |
I got something that appears to work: #4332. |
Describe the bug
The newest version of
black
started failing on our CI due to an error about not being able to parse a line that it used to be able to parse just fine.To Reproduce
On the file pyomo/contrib/pyros/util.py:
black pyomo/contrib/pyros/util.py
The resulting error is:
Expected behavior
It doesn't just error and fail on that file.
Environment
The text was updated successfully, but these errors were encountered: