-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 documentation examples of consider-using-f-string #6460
Add documentation examples of consider-using-f-string #6460
Conversation
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.
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
order = "%s and %s" % menu # [consider-using-f-string] | ||
|
||
new_order = "{1} and {0}".format(menu[0], menu[1]) # [consider-using-f-string] |
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.
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]) |
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.
Hmm, thanks for introducing me to the ¤
sign!
@@ -0,0 +1,5 @@ | |||
menu = ('eggs', 'spam') |
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.
menu = ('eggs', 'spam') | |
from string import Template | |
menu = ('eggs', 'spam', 42.42) |
order = f"{menu[0]} and {menu[1]}" | ||
|
||
new_order = f"{menu[1]} and {menu[0]}" |
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.
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} ¤" |
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.
Thank you @timmartin !
Type of Changes
Description
Adds documentation examples for the
consider-using-f-string
checker. There didn't seem to be any examples in thepylint-errors
repo that I could see, so I wrote a new one.Ref #5953