ruff icon indicating copy to clipboard operation
ruff copied to clipboard

f-string formatting: Consider format specs when choosing the preferred quotes

Open MichaReiser opened this issue 1 year ago • 3 comments

The new preview style formats

"" f'{1:""}'

as

f"{1:\"\"}"

This is correct but results in unnecessary escapes. I think we should account for the quotes in format-specs when choosing the preferred quotes for an f-string.

This can be changed here https://github.com/astral-sh/ruff/blob/113ce840a690cd59acbaf7d40d70b4352df681fe/crates/ruff_python_formatter/src/string/normalize.rs#L264-L295

CC: @dhruvmanila

MichaReiser avatar Oct 26 '24 08:10 MichaReiser