-
Notifications
You must be signed in to change notification settings - Fork 678
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
What is the recommended way to 'type hint' a loguru logger being passed around or returned by a function? #1110
Comments
the only workaround I figured so far is: from loguru import logger
Logger = type(logger)
def process_data(data: str, logger: Logger) -> None:
... |
|
good shout, the |
Actually, you should preferably not use You're facing See this answer for more details: #1101 (comment) The following solution should work fine: import loguru
def my_function(a, ctx_logger: "loguru.Logger"):
ctx_logger.debug(...) Alternatively: from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from loguru import Logger
def my_function(a, ctx_logger: Logger):
ctx_logger.debug(...) |
Wondering, how do you typehint a logger being passed around in code?
I tried using
:Logger
by importingfrom loguru import Logger
but it gives me a "ImportError: cannot import name 'Logger' from 'loguru'" errorCouldn't find a clear answer here either: https://stackoverflow.com/questions/66411218/type-hint-for-returning-loguru-logger
The text was updated successfully, but these errors were encountered: