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

Figure out possibility of tracking logger objects #6

Closed
kornicameister opened this issue Jun 13, 2020 · 1 comment · Fixed by #7
Closed

Figure out possibility of tracking logger objects #6

kornicameister opened this issue Jun 13, 2020 · 1 comment · Fixed by #7

Comments

@kornicameister
Copy link
Owner

Consider two examples

from loguru import logger

def a_foo(a: int) -> int:
    return a

# case 1
logger.debug('Should work because not lazy=True {}', a_foo)
# case 2
logger.opt(lazy=True).debug('Should fail, because callable {} has args', a_foo)

They key difference between these two calls is having one logger defined with lazy=True and the other without it. Loggers that are lazy will in fact try to call a function supplied as arg or kwarg but will succeed only if function has no arguments whatsoever. In the same time loggers that are not lazy will simple print out i.e. str(a_foo) of a function.

That said:

  • case 1 is *not something loguru-mypy should flag
  • case 2 is something loguru-mypy should flag
@kornicameister kornicameister added the enhancement New feature or request label Jun 13, 2020
@issue-label-bot
Copy link

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

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

kornicameister added a commit that referenced this issue Jun 24, 2020
Adds tracking mechanism for logger's `opt` method.
Thanks to that it is now possible to detect bad calls to logger that
are lazy and are expecting `t.Callable[[], t.Any]`

Closes: #6
@ghost ghost added the Pending PR The resolution for the issue is in PR label Jun 24, 2020
kornicameister added a commit that referenced this issue Jul 4, 2020
* Track if logger was lazy or not

Adds tracking mechanism for logger's `opt` method.
Thanks to that it is now possible to detect bad calls to logger that
are lazy and are expecting `t.Callable[[], t.Any]`

Closes: #6
@ghost ghost removed Pending PR The resolution for the issue is in PR enhancement New feature or request feature_request labels Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant