-
-
Notifications
You must be signed in to change notification settings - Fork 3k
--silent-imports prevent my code from being checked #2411
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
Comments
I'm not sure I understand this feature request. (Though it seems there are others who do, so clearly you have something important here.) Do you want mypy to exit 0 if there are errors but they are all errors that would be suppressed by If I understand your setup correctly, I think the way you are supposed to use this with |
Are you interested in silencing errors from one import in particular? You can do that with import module_without_stubs # type: ignore This will cause mypy to ignore the import error on that particular line. |
@ddfisher: I can do that for the 10 imports of my 20 files, but that's not really a clean way of doing it, isn't it? @gvanrossum: i'll give more details in a minute. |
So I have code in dirs:
I run mypy by doing:
When I do, I get type errors related to my use of the code from
And this is great, this is what I want. However, doing so will also give me errors caused by 3rd party libraries such as:
Because pytest has no stubs. Or:
Because The problems with those errors is that:
I can silence those errors with:
But doing so will also prevent mypy from following imports from
|
OK, so a reasonable feature would presumably a flag that silences
complaints about totally missing imports (like pytest or past) but doesn't
have the other effect of `--silent-imports` (which is to require stubs for
modules not explicitly listed on the command line).
I do think that in the meantime, most of your problems should go away if
you simply run `mypy tests --silent-imports src/ww <flags>` since that will
explicitly check all .py files in src/www.
|
You'd probably want 2 flags, But a better approach would be the one used in most popular linters such as flake8, pylint, etc: each type of errors have a code, and you can pass the ones you wish to ignore as a coma separated list using either the command line, a code comment or a config file. Each code is also displayed at the begining of each respective warning in the tool output, so that you can grep for it easily. This would be a more general way of solving this problem:
In the mean time I can just create a wrapper on top of mypy that filter out stdin manually an include it in the source. P.S: This doesn't seem to work:
|
The "code" idea is a good one, but also one that will require a lot of
changes to mypy, and it may not even work (there just are so many errors
that mypy can emit). In any case it requires a separate issue to track as
an idea.
|
Let me open the ticket. |
Should we close this one in favor of the other? If it's too much work, the second may never come to existence, while the first solution would. |
In the short term this one is much more actionable (in fact I recommend that you try giving it a shot). Basically there are two places that check for silent_imports, they should probably check different flags (and silent_imports may have to imply both those other flags). Also see almost_silent. All the code is in mypy/build.py. |
Ok, I'll have a look if my client give me some time for this. |
Have a look at PR #2513. I think this will help you distinguish between the two meanings of |
So the new release (0.470) has these new flags instead of --silent-imports. There's --ignore-missing imports and there's separately --follow-imports={normal,silent,skip,error}. In particular "silent" is a behavior that the old --silent-imports couldn't do. These can also be specified on a per-module basis in the mypy.ini config file. @sametmax I'm closing this issue now because I don't think we're going to be able to do much more about this. If you still have a scenario that you can't solve using the new flags please open a new issue! |
I have a tests directory containing unit tests for code in a src dir.
Currently I can either:
--silent-imports
and gets no warning for missing stubs in 3rd party library. But then any line using the code from src is not going to be checked.I need a way to silence import error, but still have my imports to be followed and checked.
The text was updated successfully, but these errors were encountered: