bpo-32262: Fix codestyle; use f-strings formatting where necessary.#4775
bpo-32262: Fix codestyle; use f-strings formatting where necessary.#47751st1 merged 5 commits intopython:masterfrom
Conversation
Lib/asyncio/windows_utils.py
Outdated
There was a problem hiding this comment.
Was an oversight, fixed it.
Lib/asyncio/base_events.py
Outdated
There was a problem hiding this comment.
No, that's logging :(
logger.debug('Get address info %s', msg) -- means that msg will be interpolated only if the logging is ON and the logging level is DEBUG. Otherwise, msg.__str__() won't be called. This is a performance thing, as __repr__() and __str__() can be expensive for some objects.
logger.debug(f'Get address info {msg}') would mean that msg.__str__() is always called, even when logging is disabled.
There was a problem hiding this comment.
In this particular case we already computed the msg, so we can inline it. In 99.9% other cases we don't want to convert logging strings.
There was a problem hiding this comment.
The problem is not only in performance.
Tools like sentry groups similar log messages basing on the message text. Calls with the same message template but different params are grouped together but pre-formatted templates are not.
As result the tool becames totally unusable: it displays tons of similar but unique messages.
Lib/asyncio/coroutines.py
Outdated
Lib/asyncio/subprocess.py
Outdated
There was a problem hiding this comment.
I think this can be made into f-string too?
| msg = [f"{host}:{port!r}"] | ||
| if family: | ||
| msg.append('family=%r' % family) | ||
| msg.append(f'family={family!r}' % family) |
There was a problem hiding this comment.
There's a remaining % family after the f-string
There was a problem hiding this comment.
Good catch, created a PR to fix this: #4787
Thanks!
https://bugs.python.org/issue32262