Prevent f-string merge quote changes with nested quotes #4498
+40
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This is my first PR to black, so any guidance is welcome.
This technically fixes, and is strongly related to, #4493, #4494, and #4495
The core theme between then is what I consider a workaround. Currently almost all of the f-string formatting code is commented out and marked todo, which includes the quote normalization. This can be bypassed by using string merging to forcibly change the quote used in f-strings, ie
"" f''
. From how it looks to me, this is not desirable, as all the same logic and edge cases will be needed whenever that code is ready, which is suboptimal. Ideally only one place would contain all the f-string logic, as from all the encountered edge cases it is quickly becoming very complex.This is also why none of those mentioned issues are closed by this PR, since their underlying causes/edge cases aren't fixed, just made inaccessible until the f-string code is worked on/some sort of resolution is made.
Since this is a regression, and a very harsh option to fix these, I'd understand if these changes are rejected, in which case this should mostly serve as a question on what to do instead.
Since this is a regression, some tests had to be removed. I was not able to find any documentation on what to do when removing tests, so I just deleted them.They have now been changed so that the output matches with the altered functionality. I also added a simplified version of #4493 as a test case to make sure this fix actually works.Checklist - did you ...
CHANGES.md
if necessary?