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

Exception traceback bug with keyword arguments #144

Closed
AnesBenmerzoug opened this issue Sep 24, 2019 · 3 comments
Closed

Exception traceback bug with keyword arguments #144

AnesBenmerzoug opened this issue Sep 24, 2019 · 3 comments
Labels
enhancement Improvement to an already existing feature

Comments

@AnesBenmerzoug
Copy link

I noticed a confusing bug when variable values are shown in tracebacks.

This bug can reproduced using the following snippet:

from loguru import logger

def f(x):
    return 1 / x

if __name__ == "__main__":
    y = 0
    with logger.catch():
        f(x=y)

    x = 0
    with logger.catch():
        f(x=x)

We notice that in the second traceback that when the named argument and the passed variable share the same name they're both treated as being variables and their values are shown.
Whereas in the first one, only the variable's value is shown.

2019-09-24 21:04:17.405 | ERROR    | __main__:<module>:11 - An error has been caught in function '<module>', process 'MainProcess' (23269), thread 'MainThread' (140248716965696):
Traceback (most recent call last):

> File "test.py", line 11, in <module>
    f(x=y)
    │   └ 0<function f at 0x7f8e32de7378>

  File "test.py", line 5, in f
    return 1 / x0

ZeroDivisionError: division by zero
2019-09-24 21:04:17.416 | ERROR    | __main__:<module>:15 - An error has been caught in function '<module>', process 'MainProcess' (23269), thread 'MainThread' (140248716965696):
Traceback (most recent call last):

> File "test.py", line 15, in <module>
    f(x=x)
    │ │ └ 0
    │ └ 0<function f at 0x7f8e32de7378>

  File "test.py", line 5, in f
    return 1 / x0

ZeroDivisionError: division by zero
@Delgan
Copy link
Owner

Delgan commented Sep 24, 2019

Thanks for the bug report. ;)

I'm not sure this can be easily fixed. The parser implemented in Loguru to display such traceback is very limited. I probably could ignore variable assignment with surrounding parentheses, though.

@AnesBenmerzoug
Copy link
Author

It's not really catastrophic. I just wanted to report it before I forgot about it.
If it would take too much work to fix, then I think it's better to invest that time and effort into something more useful.

@Delgan Delgan added the enhancement Improvement to an already existing feature label Oct 8, 2019
@Delgan
Copy link
Owner

Delgan commented Oct 26, 2019

Fixed! It will be available in the next v0.4.0 release. Thanks again for the report. 😉

@Delgan Delgan closed this as completed Oct 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement to an already existing feature
Projects
None yet
Development

No branches or pull requests

2 participants