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

Port implementation from loguru PR #3

Merged
merged 22 commits into from
Jun 13, 2020
Merged

Port implementation from loguru PR #3

merged 22 commits into from
Jun 13, 2020

Conversation

kornicameister
Copy link
Owner

Original PR: Delgan/loguru#276

@kornicameister kornicameister self-assigned this Jun 1, 2020
@kornicameister kornicameister marked this pull request as ready for review June 2, 2020 20:32
@kornicameister
Copy link
Owner Author

@Delgan I will move include corner cases in this or in another PR. I'd like to get your opinion on this PR first if you have time and don't mind :)

@kornicameister
Copy link
Owner Author

kornicameister commented Jun 3, 2020

from loguru import logger

def foo(a, b):
    a / b

try:
    foo(1, 0)
except Exception:
    logger.exception("An error occurred while executing: '{}'", foo)

Ok, I understand why this shouldn't be evaluated as an error. Point made, but this actually complicates things. Correct me, but would doing logger.opt(lazy=True).exception(...) actually tried to call foo?

Copy link
Collaborator

@Delgan Delgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, you know a lot more about mypy plugins than I do, so I don't have much useful to add. I'm learning a lot thanks to your PR. 😁

It looks good. We can improve it gradually afterwards anyway.

loguru_mypy/__init__.py Show resolved Hide resolved
@Delgan
Copy link
Collaborator

Delgan commented Jun 3, 2020

Ok, I understand why this shouldn't be evaluated as an error. Point made, but this actually complicates things. Correct me, but would doing logger.opt(lazy=True).exception(...) actually tried to call foo?

Indeed, there are a lot of special cases that can make things complicated. 😁

I'm not sure fixing this worth the trouble. It was just to give an example of the limitations we were going to face. There exist probably other edge cases of that kind, unfortunately.

A false positive is more critical than a false negative, though.

I don't know how this can be corrected. Surely we should introspect the internal attributes of the logger, if that is possible.

Your description of the lazy parameter is absolutely correct. If set to True, the logging arguments will be called and returned value will be used for the formatting. If set to False (the default), the argument could be of any type and will be formatted as is (including a function which will not be called in this case).

@kornicameister
Copy link
Owner Author

@Delgan I've created an issue #6 to approach lazy={true,false} later on.

@kornicameister kornicameister merged commit a90c131 into master Jun 13, 2020
@kornicameister kornicameister deleted the plugin_impl branch June 13, 2020 21:52
kornicameister added a commit that referenced this pull request Jun 13, 2020
* origin/master:
  Port implementation from loguru PR (#3)
  Add basic CI based on tox (#2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants