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

Implement mypy plugin for loguru #276

Closed
wants to merge 9 commits into from

Conversation

kornicameister
Copy link
Contributor

Closes: #271

@kornicameister kornicameister marked this pull request as ready for review May 29, 2020 22:13
@kornicameister
Copy link
Contributor Author

kornicameister commented May 29, 2020

@Delgan I took some liberty in designing how messages will look like. We can always tweak or adjust that. Waiting for tour feedback. There's of course a matter of documentation, but let's maybe approve code or functionality here ;)

@@ -11,7 +11,11 @@ commands =
coverage report -m

[pytest]
addopts = -l
addopts = -l --mypy-same-process --mypy-ini-file=typesafety/mypy.ini
Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's quite awkward...tox for some reason chokes on that :/. It shouldn't, I know for sure it works because this is what I have been using for some time.

testpaths =
tests/
typesafety/
log_level = DEBUG
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can drop that log_level I believe. Sorry for not doing the before.

@kornicameister
Copy link
Contributor Author

@Delgan do you have any idea how to fix that travis situation? I am not much of a travis user myself TBH :(

@Delgan
Copy link
Owner

Delgan commented Jun 1, 2020

Hey @kornicameister, thank you so much for all the work you've done!

I had absolutely no idea it was possible to achieve such a level of accuracy with mypy plugins. I tested your plugin and it totally blows my mind how you are able to detect bad usage of arguments. That's really great work.

I don't know what's wrong with Travis but I actually encounter the same error on my local computer. While running tox, --mypy-same-process and --mypy-ini-file arguments are not recognized although pytest-mypy and pytest-mypy-plugins are both installed. The pytest command works fine without tox, though. 😕

So, I didn't know what a mypy plugin looked like back to a few days. I'm quite impressed you managed to make something fully working without even needing to modify the loguru source code.

However, I don't think I want to maintain all of this with as much dedication as I'm trying for the rest of the codebase. Please tell me: what is your opinion about creating a new repository and library for loguru-mypy?

Personally, I would feel more comfortable that way. Managing such a plugin involves a lot of new things to look after, there are potential bugs [1] and edge cases [2]. Not being myself a user of mypy, I am reluctant to take the responsibility of related developments.

Of course the plugin will be mentioned in the documentation to ease discovery to those who may need it. What do you think?


[1] This raises an exception inside the plugin:

from operator import add
from loguru import logger

logger.info("Crash: {}", add)

[2] This is reported as an error while it shouldn't:

from loguru import logger

def foo(a, b):
    a / b

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

@kornicameister
Copy link
Contributor Author

kornicameister commented Jun 1, 2020

Plugins are normally not enabled by default, so this could mean we can have external repository. On the other hand that makes plugin harder to discover. Still...I have seen plugins done both ways. pydantic does embedding , but you find external repositories for SQLAlchemy though.

This is your repo, but if this plugin allows to avoid runtime problems, I would dare to suggest embedding and maintaing here. Otherwise this can go in external repo and be linked here as another extra.

Personally, I would prefer external repo just to get some "fame". But this is quite selfish and I am not really sure if that is better. TBH I wonder if checks match internal logic of loguru, which would be another reason to maintain plugin close to sources.

@Delgan
Copy link
Owner

Delgan commented Jun 1, 2020

I don't think there's a big discoverability problem because we have to mention at some point that a mypy plugin exists anyway, it's not automatic.

I agree that ideally it would be better to have all functionalities in one place. That would probably be the best. However, the more I think about it, the more I'd prefer it to be in a separate repository. At first I was not sure, but it's too much work otherwise. I'd be happy to contribute if I have the time though, but I'd have a "freer" mind.

As I prefer not to have issues reported directly here, I think it should be explicitly installed separately instead of using extra. And add a new paragraph in the documentation about type hints to mention the library and its usage.

Sorry I don't feel like integrating it directly into the codebase, but it's easier for me and it won't stop people from benefiting from your work.

@kornicameister
Copy link
Contributor Author

No worries. I wilk create a repo under my name. I was thinking about loguru organization for a while. But..yeah, we can always do that anytime later.

kornicameister added a commit to kornicameister/loguru-mypy that referenced this pull request Jun 3, 2020
@kornicameister
Copy link
Contributor Author

@Delgan let's move entire discussion to linked PR. This PR; I am closing this PR now,
Later on, I will create a new one to advertise new plugin in here.

@kornicameister kornicameister deleted the loguru_mypy branch June 3, 2020 06:32
@Delgan
Copy link
Owner

Delgan commented Jun 3, 2020

Yep, great! Thanks again. 👍

I opened an new issue about documenting the loguru-mypy plugin: #277

kornicameister added a commit to kornicameister/loguru-mypy that referenced this pull request Jun 13, 2020
Ports implementation of mypy plugin for loguru originally proposed here: Delgan/loguru#276.
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 this pull request may close these issues.

KeyError: "Attempt to overwrite 'args' in LogRecord"
2 participants