-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
mypy claims that typed code is always still perfectly good ordinary python, but that is not always the case #1103
Comments
You could ignore the problem with pylint, since it doesn't yet understand PEP 484 (although conceptually that import is not used). |
Yeah, the problem is that pylint hasn't been updated to support PEP 484. It's probably worth asking pylint developers if they are interested in adding PEP 484 support. You can request pylint to ignore the problem like this:
|
Thank you very much for your quick reply! Yes, indeed such pylint request will silence the warning. It seems I need to do more reading on my side. I didn't realize that type comments were not only in mypy, but also part of the PEP. I will ask pylint developers about that issue. In the long run I would like to avoid interfering with pylint's work, because the original code is much more complex, and if some type comments are later changed, I would like pylint to notice that some import really is not used anymore. Keep up the good work :) Looking forward to non-dev release of mypy :) |
I don't think this needs to stay open in the mypy tracker. There's nothing mypy can do, it's up to pylint, until then you can disable pylint for the typing import (we've had to do this for some internal uses too). |
here is the cross-ref for the pylint issue, on the roadmap for pylint 2.0: |
First of all, I've recently started to annotate my code, and mypy is very helpful in many cases. But I have also found a case where it is not very helpful. Below is a minimal example.
Let's say I have a file
foo_module.py
:In the above code, I either get "unused import" warning from most static analysis tools (e.g.
pylint
), or if I actually comment out the first line, to fix the issue, then, inmypy
I get "error: Name 'typing' is not defined". I cannot say I want to please everyone, but I just want to avoid being mislead by my code analysis tools.Specifically:
(1) With
import typing
intact:Part of output of
pylint foo_module.py
, misleading:Output from
mypy foo_module.py
, helpful:(2) With
import typing
as comment:No errors/warnings/etc. from
pylint foo_module.py
, rating 10/10.Output of
mypy foo_module.py
, not very helpful:... and no information about this bad behaviour in line 21
Is there any good solution for this?
The text was updated successfully, but these errors were encountered: