Skip to content

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

@dhruvmanila

Description

@dhruvmanila

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.

Metadata

Metadata

Assignees

Labels

formatterRelated to the formatterpreviewRelated to preview mode features

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions