Delgan / loguru

Python logging made (stupidly) simple
MIT License
19.82k stars 697 forks source link

from loguru._handler import StrRecord ImportError: cannot import name 'StrRecord' from 'loguru._handler' (/python3.7/site-packages/loguru/_handler.py) #1103

Open saba-nazir opened 7 months ago

saba-nazir commented 7 months ago

I am trying to use an older version of loguru i.e. loguru==0.5.3 but getting the following error.

from loguru._handler import StrRecord ImportError: cannot import name 'StrRecord' from 'loguru._handler' (/DCASE/dcase-2020-baseline-master/dcase_env/lib/python3.7/site-packages/loguru/_handler.py)

Please help.

Delgan commented 7 months ago

Hello.

The StrRecord class is an internal type that should not be imported.

If your intention was to use type hints, you should instead use the Message type to annotate your functions. This type is not defined at run-time, it only exists for type checkers, so make sure to follow the steps explained in the documentation: Type hints.

from __future__ import annotations

import loguru

def my_sink(message: loguru.Message):
    ...