You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use lazy (old style %-format) log formatting in the new pylint config #1334
Description of issue or feature request:
Using f-strings (and all types of string formatting except %-syle) in logging messages is not lazy evaluated so linters "recommend" %-style formatting.
Should we disable the related pylint warnings and use f-strings:
It's annoying to use a different formatting method for logging than anything else but the reasoning is solid... Most of our logging is not in a "hot loop" but some debug logs really might be used quite a lot (and the workaround only hides the warning, not the potential performance issue in those cases).
I think using %-style is fine for logging: logger.debug("processing, a=%s", a) but it's not a strong opinion -- in the opposite case we may want to do a quick review to identify hottest logging calls though.
changed the title [-]Decide on lazy log lormatting in the new pylint config[/-][+]Decide on lazy log formatting in the new pylint config[/+]on Apr 7, 2021
I had understood that using %-style implies means we would need to use logging-format-style=old anyway (or rather not set it as that's the default)? Pylint docs really could have more examples.
I'm proposing we use the default logging style, meaning:
use logging-format-style=old (which is default value)
stop disabling logging-not-lazy (note: this is done only in some experimental client branches -- metadata api itself hasn't needed this because there's zero logging so far 😬 )
It looks a bit uglier (other string formatting is f-strings but logging is then based on %-formatting) but:
it's a common style
it's suggested by the google style guide
it means we don't have to think about performance when writing logging code
Proposal above makes sense to me, if it's what's suggested by the style guide we probably don't even need to capture anything for this? Let's just do what our style guide suggests.
changed the title [-]Decide on lazy log formatting in the new pylint config[/-][+]Use lazy (old style %-format) log formatting in the new pylint config[/+]on May 11, 2021
Activity
sechkova commentedon Apr 6, 2021
An example approach to avoid the warnings while using f-strings which feels more like a workaround: 438c0a0
jku commentedon Apr 7, 2021
It's annoying to use a different formatting method for logging than anything else but the reasoning is solid... Most of our logging is not in a "hot loop" but some debug logs really might be used quite a lot (and the workaround only hides the warning, not the potential performance issue in those cases).
I think using %-style is fine for logging:
logger.debug("processing, a=%s", a)but it's not a strong opinion -- in the opposite case we may want to do a quick review to identify hottest logging calls though.[-]Decide on lazy log lormatting in the new pylint config[/-][+]Decide on lazy log formatting in the new pylint config[/+]sechkova commentedon Apr 8, 2021
And then there is this issue when trying to use %-style formatting but you've set up
pylinttologging-format-style=new.jku commentedon Apr 9, 2021
I had understood that using %-style implies means we would need to use
logging-format-style=oldanyway (or rather not set it as that's the default)? Pylint docs really could have more examples.Disable pylint W1201: logging-not-lazy
jku commentedon May 6, 2021
I'm proposing we use the default logging style, meaning:
logging-format-style=old(which is default value)logging-not-lazy(note: this is done only in some experimental client branches -- metadata api itself hasn't needed this because there's zero logging so far 😬 )It looks a bit uglier (other string formatting is f-strings but logging is then based on %-formatting) but:
joshuagl commentedon May 10, 2021
Proposal above makes sense to me, if it's what's suggested by the style guide we probably don't even need to capture anything for this? Let's just do what our style guide suggests.
[-]Decide on lazy log formatting in the new pylint config[/-][+]Use lazy (old style %-format) log formatting in the new pylint config[/+]Metadata API/pylintrc: Use old style logging