-
Notifications
You must be signed in to change notification settings - Fork 697
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
Change "mesage" type hint of logging methods from "str" to "LiteralString" #1206
Comments
f-string is faster and more readable than implicit format. So some users just use f-string at logging message if they know a message will always be logged, for example, as warning message or error message. But the problem is, f-string is not always So this will be a type error https://docs.python.org/3/library/typing.html#typing.LiteralString |
It would be great for logging frameworks if simple f-strings could be evaluated lazily by currying all required context variables until |
@trim21 You're correct. It would be too much of a burden for users. I still believe using
However, Loguru is designed to be flexible, and users have different expectations and habits. It's not possible to impose this. @reneleonhardt Python does not allow this. You need to use an auxiliary function, for example the |
why? I thought this is a typing only change in |
I mean, because it avoids formatting the arguments if the log level is too high and that the message won't be logged anyway. |
Ok, I get it. But it lead to worse perf for always logged line if f-string can't be used. |
It should help with catching this kind of problem referenced in the documentation:
A type checker would reject such code if
message
is not aLiteralString
.The text was updated successfully, but these errors were encountered: