Repository navigation
Conversation
|
FWIW I prefer keeping the leading f's when some part of the implicitly concatenated string uses formatting (and will intentionally add them), to make the string prefixes aligned... |
|
I have mixed feelings. On one hand I agree with @anntzer that keeping the prefixes lined up in helps keep the code readable. On the other hand I have had a linter catch "I meant to make this an f-string but forget the f" on a couple of occasions. A suggestion that I think everyone will be against, we could use an explicit |
|
I would rather fix the linters to allow (perhaps as an option) the "there's an f just to align with another f in the implicitly concatenated string". For example, pylint seems smart enough to not emit warnings in that case (while warning for unnecessary f's if there's no interpolation anywhere). Also, note that what you mention seems to be the opposite case (catching a missing f, not an unneeded one). |
|
I tend to agree with @anntzer. This is a very general styling topic. Are we aware of any recommendations/best practice of other libraries? |
|
I'll close, but feel free to reopen if we think this is really needed. |
PR Summary
No need for an f-string if no formatting is done.
As I stumbled upon a line that was mentioned in #21959 I also fixed that.
Closes #21968 (except that there is no test for it here).
PR Checklist
Tests and Styling
pytestpasses).flake8-docstringsand runflake8 --docstring-convention=all).Documentation
doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).