-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Rule EM102 cause panic assertion failed: self.start_locations.is_empty()
#7736
Comments
@dhruvmanila - Do you mind taking a look at this one? It's f-string related (in the indexer, we have a lingering start that wasn't matched to an end). |
Yes, will look at it in a bit |
This is similar to #6988. The problem here is that the original string is a triple-quoted f-string but the generator doesn't generate that (triple quotes) and instead just gives a single quoted string: -raise AttributeError(f"""Attribute(s) {", ".join([f"'{dupe}'" for dupe in intersection])} was/were provided twice.""")
+msg = f"Attribute(s) {', '.join([f\"'{dupe}'\" for dupe in intersection])} was/were provided twice."
# ^^ ^^
+raise AttributeError(msg) The transformed code is the one which raises this error because it's actually invalid syntax (the nested f-string quote is being escaped here marked at This is a suggested fix so it could be solved once applicability changes are merged. I'm not sure we can do anything else here as the f-string code in the |
I mean, in this specific case, we could also move towards using the |
By this, do you mean in terms of single vs triple-quoted string generation? |
Yeah, e.g., preserving quote styles in the generator. |
I've updated the code to use |
## Summary This PR fixes the bug where the generated fix for `EM*` rules would replace a triple-quoted (f-)string with a single-quoted (f-)string. This changes the semantic of the string in case it contains a single-quoted string literal. This is especially evident with f-strings where the expression could contain another string within it. For example, ```python f"""normal {"another"} normal""" ``` ## Test Plan Add test case for triple-quoted string and update the snapshots. fixes: #6988 fixes: #7736
Ruff 0.0.291 (latest changes from main branch)
file content:
error
python_compressed.zip
The text was updated successfully, but these errors were encountered: