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

Consider nudging users towards using f-strings #3592

Closed
NeilGirdhar opened this issue May 5, 2020 · 2 comments · Fixed by #4796
Closed

Consider nudging users towards using f-strings #3592

NeilGirdhar opened this issue May 5, 2020 · 2 comments · Fixed by #4796
Labels
Enhancement Improvement to a component Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors

Comments

@NeilGirdhar
Copy link

NeilGirdhar commented May 5, 2020

Python 3.5 is end-of-life in September 2020. Since Python 3.6 introduced f-strings, there is no good reason to interpolate literal strings with the string interpolation operator

'Python %f' % version

or the format method

'Python {}'.format(version)

—except when the arguments involve unpacking:

'Python {} or {}`.format(*versions)

Can we consider a pylint warning to nudge users towards using f-strings when possible? It would be extremely helpful to write the f-string for them. For example:

a.py:1:0: W999: Not using f-string: f"Python {version}" (not-using-fstring)

What do you think?

@TylerYep
Copy link

TylerYep commented May 5, 2020

Seconded, especially since f-strings are a lot faster in practice as well.

@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement Improvement to a component label May 10, 2020
@Pierre-Sassoulas
Copy link
Member

It seems reasonable to me. I just think that the message should be a convention instead of a warning.

@Pierre-Sassoulas Pierre-Sassoulas added Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors labels Apr 24, 2021
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Aug 19, 2021
This adds a checker for normal strings which are formatted
with `.format()` or '%'.
The message is a convention to nudge users towards using f-strings.
This closes PyCQA#3592
DanielNoord added a commit to DanielNoord/pylint that referenced this issue Aug 20, 2021
This adds a checker for normal strings which are formatted
with ``.format()`` or '%'.
The message is a convention to nudge users towards using f-strings.
This closes PyCQA#3592
Pierre-Sassoulas added a commit that referenced this issue Aug 30, 2021
* Add ``consider-using-f-string`` checker
This adds a checker for normal strings which are formatted
with ``.format()`` or '%'.
The message is a convention to nudge users towards using f-strings.
This closes #3592

* Update pylint code to use f-strings
After adding `consider-using-f-strings` the codebase showed numerous
cases of formatting which could be f-strings.
This commit changes most of these to become f-strings, or adds ignores.

* Apply suggestions from code review

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
return42 added a commit to searxng/searxng that referenced this issue Sep 17, 2021
Pylint 2.11 added [1][2]

consider-using-f-string:
  Emitted when .format() or '%' is being used to format a string.

We're not ready to enforce f-strings everywhere, so just disable this new
warning.

[1] https://pylint.pycqa.org/en/latest/whatsnew/2.11.html
[2] PyCQA/pylint#3592

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Improvement to a component Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants