-
Notifications
You must be signed in to change notification settings - Fork 705
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
Flesh out the few remaining incomplete annotations #316
Conversation
`_Logger.add`'s `sink` parameter.can accept all of the same types as `_HandlerConfig.sink`. 'extra' is `Dict[str, Any]` where in reality the value is anything that can be serialised and the key is the name of a keyword argument. `parse` overloads can be implemented without @staticmethod since `_Logger` is not part of the public API (the logger is a singleton). Renamed `Logger` to `_Logger` since `Logger` does not exist at runtime.
Hey @layday, thanks for contributing to Loguru! Let me clarify why type hints are implemented in this way.
The For example,
I deliberately made I don't expect this to be used very much in practice, but still it's possible and nothing forbids it. I don't think we should restrict the user on this point.
Clever. Would there be a problem if the signature between the type hint and the implementation are different (since there is no
The from __future__ import annotations
def prepare_logger(logger: loguru.Logger):
logger.configure(...) |
Apologies, I missed that.
Thank you for clarifying. In that case, I would be inclined to annotate it with
I don't think so - not unless a type checker were to attempt to infer the types from source, which, ahem, should never happen in the presence of a
That does make sense but exposing a name that does not exist at runtime is rather unusual. Users would still be able to access the from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
Logger = type(loguru.logger)
def prepare_logger(logger: Logger):
logger.configure(...) I'll revert it. |
Revert extraneous arguments from `add` overload. Re-annotate `extra`. Re-expose `Logger`.
Whoops, I pinged both |
Thanks for the update! One final observation: shouldn't I will fix it during the merge so you don't have to bother updating the PR once again.
Yes is it. 😄
You can select the part of the message you want to quote and type |
Oh cool, I didn't know that - thanks!
You are correct - I think it was a find/replace that went wrong. |
Finally merged, thanks for your time @layday! |
_Logger.add
'ssink
parameter.can acceptall of the same types as
_HandlerConfig.sink
.'extra' is
Dict[str, Any]
where inreality the value is anything that can be
serialised and the key is the name of a keyword
argument.
parse
overloads can be implemented without@staticmethod since
_Logger
is not part of thepublic API (the logger is a singleton).
Renamed
Logger
to_Logger
sinceLogger
does not exist at runtime.