-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Convert all string concatenations and brace-formatting to f-string formatting #8332
Comments
is there actually much advantage to proactively going through and changing all the existing formatting operations? I'd have thought there was a much higher chance of introducing bugs by doing so. |
not if care is taken while going through them, and the "less bug-prone" part is in regards to how-to-use formatting in the future, because other formatting relies on careful ordering of the arguments in and out of the template, while f-strings have the actual referred variable right there in the template itself, which will by itself eliminate the possibility for misplaced variables |
pretty sure that no matter how much care you take, changing code is more likely to introduce bugs than not doing so ;)
well quite. that sounds like a good argument for using them for future code, whereas the best that can be said for changing existing code is "consistency". So sure, it's probably a good thing to do, but given the effort required, it doesn't feel like a massive priority. |
Looking at https://github.com/asottile/pyupgrade, this seems easily done with |
A discrete downside to this is that, when using the logging module, it forces the evaluation of log messages, even if the message will not be logged (e.g. the logger's level isn't high enough). |
@clokep what do you mean? |
I don't know anything about pyupgrade, I'm just commenting on the title of this which says to convert formatting to f-strings. |
I'm leaving alone |
I would not call this obvious from the description. 😄 There was no mention of leaving logger calls alone.
I'm glad that we're in agreement! |
#9744 is already covering this |
Description:
If/when synapse drops support for 3.5, convert all brace-formatting (
"{}".format(obj)
, percent-formatting ("%s" % obj
) and string concatenations ("object:" + obj"
) with f-strings (f"{obj}"
)This approach is cleaner and less bug-prone as variable reference and exacting string template is combined into one.
(When synapse drops support for 3.5, i'd be happy to take up the task of converting everything)
The text was updated successfully, but these errors were encountered: