Skip to content

"Internal error" while logging non-string messages #49

@Delgan

Description

@Delgan

Hi! :)

It seems that some expressions are not recognized and generate an internal error in the plugin. It happens due to the assert here:

assert isinstance(log_msg_expr, StrExpr), type(log_msg_expr)

Actually, the argument does not necessarily needs to be string. Here are some examples that generate an error.

from loguru import logger

logger.info(123)
from loguru import logger

logger.info("foo" + "bar")
from loguru import logger

foo = "bar"
logger.info(foo)
from loguru import logger

logger.info(f"{foobar}")

Which results in:

a.py:3: error: INTERNAL ERROR -- Please try using mypy master on Github:
https://mypy.rtfd.io/en/latest/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 0.790
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 3766, in accept
  File "mypy/checkexpr.py", line 263, in visit_call_expr
  File "mypy/checkexpr.py", line 340, in visit_call_expr_inner
  File "mypy/checkexpr.py", line 817, in check_call_expr_with_callee_type
  File "mypy/checkexpr.py", line 880, in check_call
  File "mypy/checkexpr.py", line 1532, in check_overload_call
  File "mypy/checkexpr.py", line 1675, in infer_overload_return_type
  File "mypy/checkexpr.py", line 876, in check_call
  File "mypy/checkexpr.py", line 988, in check_callable_call
  File "mypy/checkexpr.py", line 725, in apply_function_plugin
  File "/home/delgan/Programmation/loguru-mypy/loguru_mypy/__init__.py", line 99, in _loguru_logger_call_handler
    assert isinstance(log_msg_expr, StrExpr), type(log_msg_expr)
AssertionError: <class 'mypy.nodes.IntExpr'>
a.py:3: : note: use --pdb to drop into pdb

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions