Skip to content
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

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

Closed
Delgan opened this issue Oct 28, 2020 · 4 comments
Closed

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

Delgan opened this issue Oct 28, 2020 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@Delgan
Copy link
Collaborator

Delgan commented Oct 28, 2020

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
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.96. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@ThibaultLemaire
Copy link
Contributor

ThibaultLemaire commented Jan 4, 2021

As mentioned in #42 (comment) I'd like to work on the 3rd case (variables):

from loguru import logger

foo = "bar"
logger.info(foo)

ThibaultLemaire added a commit to ThibaultLemaire/loguru-mypy that referenced this issue Jan 4, 2021
Partially fixes kornicameister#49

Note that mypy _cannot_ type-check a format expression if it is not Final.
E.g.:

```python
from loguru import logger
from typing import Final

foo: Final = "bar"
logger.info(foo, 1)  # error: Not all arguments converted during string formatting
foo = "bar"
logger.info(foo, 1)  # no error (and will fail at runtime)
```

This is a limitation with mypy and I don't think we can do much about it
@ghost ghost added the Pending PR The resolution for the issue is in PR label Jan 4, 2021
ThibaultLemaire added a commit to ThibaultLemaire/loguru-mypy that referenced this issue Jan 4, 2021
Fixes example 3 of kornicameister#49

Note that mypy _cannot_ type-check a format expression if it is not Final.
E.g.:

```python
from loguru import logger
from typing import Final

foo: Final = "bar"
logger.info(foo, 1)  # error: Not all arguments converted during string formatting
foo = "bar"
logger.info(foo, 1)  # no error (and will fail at runtime)
```

This is a limitation with mypy and I don't think we can do much about it
@ghost ghost removed the Pending PR The resolution for the issue is in PR label Jan 4, 2021
ThibaultLemaire added a commit to ThibaultLemaire/loguru-mypy that referenced this issue Jan 4, 2021
Fixes example 3 of kornicameister#49

Note that mypy _cannot_ type-check a format expression if it is not Final.
E.g.:

```python
from loguru import logger
from typing import Final

foo: Final = "bar"
logger.info(foo, 1)  # error: Not all arguments converted during string formatting
foo = "bar"
logger.info(foo, 1)  # no error (and will fail at runtime)
```

This is a limitation with mypy and I don't think we can do much about it
ThibaultLemaire added a commit to ThibaultLemaire/loguru-mypy that referenced this issue Jan 6, 2021
Fixes example 3 of kornicameister#49

Note that mypy _cannot_ type-check a format expression if it is not Final.
E.g.:

```python
from loguru import logger
from typing import Final

foo: Final = "bar"
logger.info(foo, 1)  # error: Not all arguments converted during string formatting
foo = "bar"
logger.info(foo, 1)  # no error (and will fail at runtime)
```

This is a limitation with mypy and I don't think we can do much about it
@kornicameister
Copy link
Owner

kornicameister commented Jan 19, 2021

Ok, I believe we have number 3 fixed, like @ThibaultLemaire did in b608dc0.
I am closing this issue but fear not ( :P ) there will be issues scoped to figure out remaining points brought up by @Delgan.

I believe those are:

  • OpExpr (an expression like 2+1).
  • CallExpr (which seems to be a case for f-string but only those that use an argument)

If I made a mistake, please correct me here.

@kornicameister
Copy link
Owner

Looks like another funny bit has been implemented as part of #81. That will give us a single argument variation on non-str arguments, if i am correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants