Forbid using `f` strings
See original GitHub issueI don’t see any reasons why we should use them.
Let’s use .format()
instead.
P.S. For a reason we can not forbid %
usage: https://github.com/gforcada/flake8-pep3101/issues/23
Issue Analytics
- State:
- Created 5 years ago
- Reactions:20
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Pylint: How to fix "c0209: formatting a regular string which ...
Learn how to fix this new Pylint rule that raises: 'formatting a regular string which could be a f-string (consider-using-f-string)' error.
Read more >consider-using-f-string / C0209 - Pylint
Description: Used when we detect a string that is being formatted with format() or % which could potentially be a f-string. The use...
Read more >Python3 f-strings: how to avoid having to escape literal curly ...
I am aware that one can use the older syntax of e.g. div {color: %s} % color , 'text {}'.format(abc) or string templates...
Read more >PEP 498 – Literal String Interpolation
F -strings provide a way to embed expressions inside string literals, using a minimal syntax. It should be noted that an f-string is...
Read more >When not to use f-strings? - Python Forum
format method: PyFormat: Using % and .format() for great good!. No f-strings but I believe it can be source of some ideas. I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
.format()
can be short too:But, for me being shorter is not a valid argument. What matters is:
Readability
My old habits put
.format()
overf
, since I am just used to it. This is highly subjective, but that’s my point.But, what really makes a difference is that we can not put logics inside
.format()
, while we can do bizarre things insidef
strings:That is so wrong, that I can not allow this.
Performance
Yes,
f
is slightly faster than.format()
. But it is safe to say that they are almost the same.Consistency
I don’t see any use-cases of
f
strings that can not be covered with.format()
. So, let’s stick to a single way to format strings.I guess, @sobolevn really wants just linters for f-strings code and some heuristic to forbid doing complex things inside f-strings.