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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter: handle comments, quotes, and expressions inside f-strings #7594

Closed
dhruvmanila opened this issue Sep 22, 2023 · 0 comments · Fixed by #9642
Closed

Formatter: handle comments, quotes, and expressions inside f-strings #7594

dhruvmanila opened this issue Sep 22, 2023 · 0 comments · Fixed by #9642
Assignees
Labels
formatter Related to the formatter preview Related to preview mode features

Comments

@dhruvmanila
Copy link
Member

This issue is to kickoff a discussion around the formatting for f-strings. With PEP 701, f-strings changes the behavior with what kind of syntax is allowed:

  1. Comments inside f-strings:
# comment 0
f"""
{ # comment 1
    # comment 2
    foo # comment 3
    # comment 4
}"""  # comment 5
  1. F-strings can be nested within f-strings
f"first {f"second {f"third ..."} second"} first"
  1. Quotes can be repeated inside nested f-strings (for both strings and f-strings)
f"double quotes {"same quotes in strings" + f"same quotes in f-strings"}"

This means that the formatter needs to be updated to possibly handle f-strings on it's own. Currently, it's handled as part of string formatting.

@dhruvmanila dhruvmanila added the formatter Related to the formatter label Sep 22, 2023
@MichaReiser MichaReiser added this to the Formatter: Beta milestone Sep 22, 2023
@dhruvmanila dhruvmanila changed the title Formatter: handle comments and quotes for f-strings Formatter: handle comments, quotes, and expressions inside f-strings Dec 11, 2023
@MichaReiser MichaReiser added the preview Related to preview mode features label Feb 14, 2024
@dhruvmanila dhruvmanila linked a pull request Feb 16, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter preview Related to preview mode features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants