-
Notifications
You must be signed in to change notification settings - Fork 672
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
Type and definition mismatch for Logger class #1101
Labels
question
Further information is requested
Comments
Hi @ukalwa. Loguru references type hints through a stub file only. The types are not accessible at run-time, they only exist in the context of type checkers execution. You should use postponed evaluation of type hints, either using strings: import loguru
def setup_logger(_logger: "loguru.Logger") -> "loguru.Logger":
... Or using a from __future__ import annotations
def setup_logger(_logger: loguru.Logger) -> loguru.Logger:
... If you want to import only specific types, you can also rely on the from __future__ import annotations
import typing
if typing.TYPE_CHECKING:
from loguru import Logger
def setup_logger(_logger: Logger) -> Logger:
... See Loguru documentation: Type hints. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I am importing and using Logger class (for typing purposes) as shown below, I am getting an import error like
ImportError: cannot import name 'Logger' from 'loguru'
.Turns out it is imported as _Logger in
__init__.py
and thereby a mismatch between type and definition.loguru/loguru/__init__.py
Line 12 in 70e9df2
The text was updated successfully, but these errors were encountered: