Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[.pylint] % formatting in logging #9

Open
lachmanfrantisek opened this issue Oct 29, 2018 · 5 comments
Open

[.pylint] % formatting in logging #9

lachmanfrantisek opened this issue Oct 29, 2018 · 5 comments

Comments

@lachmanfrantisek
Copy link
Member

We have many occurrences of this:

Use % formatting in logging functions and pass the % parameters as arguments

We are mostly using new .format syntax -- is this optimalisation really necessary?


PyLint_W1202

https://stackoverflow.com/questions/34619790/pylint-message-logging-format-interpolation

@TomasTomecek
Copy link
Member

I personally prefer using logger.debug("hi there %s", the_dude) over .format(. Hence for me the warning is useful. It's really up to you, we can vote.

@jpopelka
Copy link
Member

Yeah, I constantly poke people in comments about it, but some people can't even be consistent and chose one way how to format strings because they give a f* about warnings.

So let's be pragmatic for a moment:
The only way (I see) why using % over format() (or better f-strings) is that the string doesn't need to be formatted if it's in debug() and you run the code with info or warn.
With nowadays computing power, I don't think that difference is even perceptible.
On the other hand, using f-strings over % makes reading others' code sooo much easier that I'm inclined to consider this warning obsolete.

@TomasTomecek
Copy link
Member

@jpopelka please, teach us f-strings then :)

@jpopelka
Copy link
Member

please, teach us f-strings then :)

not sure how to react, since I know all (but one) of us know it.

What about ?

string = f"Hello {some_variable}. You are {another_variable}."

is there anything else you need to know ?

@TomasTomecek
Copy link
Member

TomasTomecek commented Oct 31, 2018

Actually half of this: https://pyformat.info/

I always forget how to do %r with .format and have no idea how to do that with f-strngs. Also padding and floats are used so rarely that I keep forgetting those constantly.

Some time ago I started this cheatsheet: https://github.com/TomasTomecek/mysterious-keybinds#python Having a clear table which all of us could print and stuff behind our monitors would be mind-blowing. Probably even nobel price-winning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants