Skip to content

Adds the --ignore-missing-stubs command line option #4491

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

Closed
wants to merge 4 commits into from

Conversation

boompig
Copy link

@boompig boompig commented Jan 19, 2018

--ignore-missing-stubs MODULE-1 [MODULE-2 ...] will suppress missing typeshed information for the specified modules

Includes tests for both command-line and config file invocations

Fixes issue #3905

--ignore-missing-stubs MODULE-1 [MODULE-2 ...] will suppress missing
typeshed information for the specified modules

Fixes issue python#3905
@boompig boompig changed the title Adds the --ignore-missing-stubs flag Adds the --ignore-missing-stubs command line option Jan 19, 2018
@gvanrossum
Copy link
Member

Thanks! I have one issue with the UI design though. The way argparse parses flags with an arbitrary number of values unfortunately makes it hard to specify that flag followed by a filename (meant as a positional arg):

mypy --ignore-missing-stubs foo bar x.py

will complain that there's no target module, package or file. My suggested solution is to use a comma as a separator instead; you'll have to do a little parsing of the (single) argument to make that work, and it'll require some more work for mypy.ini.

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 19, 2018

What about naming it --ignore-missing-modules instead and making it possible to ignore arbitrary modules? The third party module list in mypy is not at all complete. Besides, it could be used for ignoring user modules as well.

It would be nice if there was an easy way to ignore an entire package. Maybe the target should act as a prefix, ignoring all submodules as well? Or we could support the * wildcard.

The documentation should probably cover packages and submodules as well.

@gvanrossum
Copy link
Member

Note that IIRC it's possible to ignore specific modules by putting either ignore_missing_imports = True or follow_imports = skip in a module-specific section in mypy for the module to be ignored. (Can someone please verify that this works?)

The new syntax is --ignore-missing-stubs module-1[,module-2,...,module-n]
@boompig
Copy link
Author

boompig commented Jan 19, 2018

The above commit has the new syntax and additional tests to make sure behavior is consistent with the config files.

@boompig
Copy link
Author

boompig commented Feb 1, 2018

Can anyone help merge this PR? This feature would be very useful to several projects I'm working on.

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 1, 2018

@boompig To move forward with this, please respond to my comments above.

@boompig
Copy link
Author

boompig commented Feb 1, 2018

@JukkaL

What about naming it --ignore-missing-modules instead and making it possible to ignore arbitrary modules?

I think this may be confused with --ignore-missing-imports. Using stubs makes it clear that you're not ignoring the module, you're just ignoring the lack of a stubs file. But if you feel strongly, I don't mind changing it.

The third party module list in mypy is not at all complete.

It's missing numpy and pandas, for example.

Besides, it could be used for ignoring user modules as well.

This is a good idea, though in practice I wonder how often this comes up for a user who has chosen to use mypy...

It would be nice if there was an easy way to ignore an entire package. Maybe the target should act as a prefix, ignoring all submodules as well? Or we could support the * wildcard.

I like the idea of a * wildcard. This is a very good idea. Not sure if I have the bandwidth to work on this though, since it's a non-trivial change.

The documentation should probably cover packages and submodules as well.

Can you explain further?

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 1, 2018

I think this may be confused with --ignore-missing-imports. Using stubs makes it clear that you're not ignoring the module, you're just ignoring the lack of a stubs file. But if you feel strongly, I don't mind changing it.

The current approach only works for certain third party modules that happen to be whitelisted in mypy. It doesn't allow ignoring missing stdlib stubs and non-whitelisted third party modules, which is too limiting (and also confusing).

We could continue to use --ignore-missing-stubs as the name of the option but allow ignoring arbitrary modules, not just whitelisted third party ones. The new note could be generated for known modules only. It would be better to generate the note for both known third party and stdlib modules, however, instead of just third party modules.

The documentation should probably cover packages and submodules as well.

Can you explain further?

You could mention that ignoring package x doesn't affect imports from submodules of x such as x.y. It's necessary to list each submodule that is being ignored separately, and this is not clear from the current documentation.

@emmatyping
Copy link
Member

I'm not so sure this is needed.

Note that IIRC it's possible to ignore specific modules by putting either ignore_missing_imports = True or follow_imports = skip in a module-specific section in mypy for the module to be ignored. (Can someone please verify that this works?)

I did test this and it worked fine.

@gvanrossum
Copy link
Member

I did test this and it worked fine.

If you're thinking of #3789, according to the OP it still parses those modules?

@emmatyping
Copy link
Member

emmatyping commented Feb 26, 2018

If you're thinking of #3789, according to the OP it still parses those modules?

Interesting. It seems if I have:

mod
| - __init__.py
| - lib.py

it will skip it with mypy -m mod but not mypy mod.

@gvanrossum
Copy link
Member

it will skip it with mypy -m mod but not mypy mod.

Ah, I know why. The latter invocation searches the folder named mod for .py[i] files, and it parses those regardless of the other settings. Though I'm now curious how the code in #3789 avoids that.

@msullivan
Copy link
Collaborator

Agree that this isn't needed.
To suppress use of a typeshed package that is missing, you can do

[mypy-module.*]
ignore_missing_imports = True

To suppress use of a typeshed package this is present but that you want to suppress anyways, you can use:

[mypy-module.*]
follow_imports = skip
follow_imports_for_stubs = True

(the follow_imports_for_stubs option is recent and post-dates this PR, but was a smaller hammer)

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.

5 participants