astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
32.92k stars 1.1k forks source link

F-string formatting adds unnecessary space after `**` operator #14487

Open dhruvmanila opened 3 hours ago

dhruvmanila commented 3 hours ago

Consider the following source code:

f"aaaaaaaaaaaaaaaaaaaaaaaaaa {10**27} bbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc"

Running ruff format --preview:

f"aaaaaaaaaaaaaaaaaaaaaaaaaa {10** 27} bbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccc"

Playground: https://play.ruff.rs/80926d6e-f183-4631-94ce-f1702502a0e0

Found in https://github.com/astral-sh/ruff/pull/14454#issuecomment-2488346686

MichaReiser commented 3 hours ago

Huh, that's weird

MichaReiser commented 3 hours ago

Oh, is it because of the inner group and the entire line exceeds the line length. We might need to remove if_group_breaks from RemoveSoftLinesBuffer

MichaReiser commented 3 hours ago

this could be annoying

dhruvmanila commented 3 hours ago

Oh, is it because of the inner group and the entire line exceeds the line length.

Yeah, and we use RemoveSoftLinesBuffer but that doesn't remove the space as you've mentioned.