Add documentation examples of consider-using-f-string#6460
Merged
Pierre-Sassoulas merged 4 commits intopylint-dev:mainfrom Apr 27, 2022
Merged
Conversation
4 tasks
Pierre-Sassoulas
requested changes
Apr 25, 2022
Member
There was a problem hiding this comment.
Thank you for the documentation ! I think we need a detail.rst saying f-string performance at a lot better with a link to this tweet from a python core dev : https://twitter.com/raymondh/status/1205969258800275456. Also added more technical f-string with float formatting because often it's not known that this kind of thing can be done with fstring too
Comment on lines
+3
to
+5
| order = "%s and %s" % menu # [consider-using-f-string] | ||
|
|
||
| new_order = "{1} and {0}".format(menu[0], menu[1]) # [consider-using-f-string] |
Member
There was a problem hiding this comment.
Suggested change
| order = "%s and %s" % menu # [consider-using-f-string] | |
| new_order = "{1} and {0}".format(menu[0], menu[1]) # [consider-using-f-string] | |
| old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string] | |
| beginner_order = menu[0] + "and " + menu[1] + ": " + str(menu[2]) + " ¤" | |
| joined_order = "and ".join(menu) | |
| format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2]) # [consider-using-f-string] | |
| named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(eggs=menu[0], spam=menu[1], price=menu[2]) # [consider-using-f-string] | |
| template_order = Template('$eggs and $spam: $price ¤').substitute(eggs=menu[0], spam=menu[1], price=menu[2]) |
Contributor
Author
There was a problem hiding this comment.
Hmm, thanks for introducing me to the ¤ sign!
| @@ -0,0 +1,5 @@ | |||
| menu = ('eggs', 'spam') | |||
Member
There was a problem hiding this comment.
Suggested change
| menu = ('eggs', 'spam') | |
| from string import Template | |
| menu = ('eggs', 'spam', 42.42) |
Comment on lines
+3
to
+5
| order = f"{menu[0]} and {menu[1]}" | ||
|
|
||
| new_order = f"{menu[1]} and {menu[0]}" |
Member
There was a problem hiding this comment.
Suggested change
| order = f"{menu[0]} and {menu[1]}" | |
| new_order = f"{menu[1]} and {menu[0]}" | |
| f_string_order = f"{menu[0]} and {menu[1]}: {menu[2]:0.2f} ¤" |
Pierre-Sassoulas
approved these changes
Apr 27, 2022
Member
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
Thank you @timmartin !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Changes
Description
Adds documentation examples for the
consider-using-f-stringchecker. There didn't seem to be any examples in thepylint-errorsrepo that I could see, so I wrote a new one.Ref #5953