-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Decide how to handle comments with debug expressions in f-strings #112243
Comments
I think we should remove the comment and keep the newline. |
I expected the example to produce "SyntaxError: unterminated f-string literal (detected at line 1)", just as it would without the '{'. But given that '{' escapes the newline, I also expect it to escape the octothorpe, just as it does now. So I consider the current behavior correct. |
@terryjreedy not sure I follow your reasoning, what do you mean when you say that "given that '{' escapes the newline"? There is nothing here being scaped no? Inside an f-string expression now any expression can be made as if it written between parentheses. The key of this issue is the debug expression here |
I was using a different analogy for my expectation. Even better, I think, are these: As for newlines: whitespace before and after |
If the expression component of an f-string requires comments, you're probably doing something horribly wrong. That being said, keeping the comment in the resulting string is likely to be the least surprising behavior. Either that or forbidding comments inside f-strings altogether. |
I also think that the comment should be ignored, while the newline should be kept. |
…essions (pythonGH-112284) (cherry picked from commit d59feb5) Co-authored-by: Pablo Galindo Salgado <[email protected]>
After PEP 701, having comments mixed with debug expressions is possible but the interactions has not been discussed. For instance, consider this code:
this produces:
which is surprising. What we should do here? I think we should probably not include the comment but we should agree on the behavior before a PR can be made
Linked PRs
The text was updated successfully, but these errors were encountered: