good_smell icon indicating copy to clipboard operation
good_smell copied to clipboard

Use f-string instead of string.format

Open Tadaboody opened this issue 7 years ago • 1 comments

New smell

Smelly code

"a={},b={}".format(a,b)

Fixed code

f"a={a},b={b}"

Potential gotchas:

  • [ ] warn only on py3.6+
  • [ ] if the expression has quotes in it make sure to alternate single quotes '' and double quotes ""
  • [ ] Don't warn if the formatted string isn't called directly (if the string is waiting for later)

Tadaboody avatar Dec 03 '18 11:12 Tadaboody

Can look at https://github.com/asottile/pyupgrade which already implemented this for """insparation"""

Tadaboody avatar Dec 08 '18 01:12 Tadaboody