-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add Consider-using-f-string
checker
#4796
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
Add Consider-using-f-string
checker
#4796
Conversation
7fe2a32
to
9e64e5f
Compare
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 pylint-dev#3592
9e64e5f
to
8bd4d79
Compare
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.
8bd4d79
to
8bc9668
Compare
Pull Request Test Coverage Report for Build 1176970109
💛 - Coveralls |
Many changes in the second commit of this PR. However, I think they are warranted as f-strings are considerably faster, see here for example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huge cleanup work alongside a very useful new checker, thanks a lot ! Did you check the change in performance by using the benchmark result locally ? If f-string are faster if could be another good news 😄 I have minor comments, let me know what you think.
@@ -14,7 +14,6 @@ | |||
renamed_logging.warn('%s' + ' the rest of a single string') # [logging-not-lazy] | |||
renamed_logging.log(renamed_logging.INFO, var_name + var) # [logging-not-lazy] | |||
|
|||
var_name = 'Var:' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this line ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think it added anything after line 8. Seems a duplicate
Co-authored-by: Pierre Sassoulas <[email protected]>
Should be good to go now for I did not do the benchmarks, you might want to do them but I think there should be a performance increase. At least for some of the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, great checker and great clean up too !
Regarding the performance increase, I also think that it should increase because of f-string but we'd switch to f-string even with a sligth decrease in performance because of the readability and modernity :) |
I don't think this should have been part of the IMO this should even move to a new extension. |
doc/whatsnew/<current release.rst>
.Type of Changes
Description
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