Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to totally ignore all of the MyPy errors in specific project packages?

Is there a way to ignore all of the errors in certain packages within my project?

Some of the code in my project is compiled Protocol Buffers code which doesn't pass a MyPy check. It all lives within a directory /myproj/generated/proto.

Here's what I have in my mypy config file:

[mypy-myproject.generated]
ignore_missing_imports = True
ignore_errors = True

What can I add to this to make it ignore all error messages generated from an analysis of anything that's inside of myproject.generated?

This is a duplicate of a question on GitHub.

like image 220
Salim Fadhley Avatar asked Jan 07 '19 13:01

Salim Fadhley


People also ask

How do I ignore MYPY errors?

You can use a special comment # type: ignore[code, ...] to only ignore errors with a specific error code (or codes) on a particular line. This can be used even if you have not configured mypy to show error codes. Currently it's only possible to disable arbitrary error codes on individual lines using this comment.

How do I run MYPY with config file?

To use this config file, place it at the root of your repo and run mypy. This config file specifies three global options in the [mypy] section. These three options will: Type-check your entire project assuming it will be run using Python 2.7.


Video Answer


2 Answers

You can use a glob.

[mypy-myproject.generated.*]
ignore_errors = True

But you have to assure that you have __init__.py in /generated

like image 67
Gabriel Viviani Avatar answered Oct 29 '22 17:10

Gabriel Viviani


You can also use ignore an entire folder or file via the exclude option.

Here is an example of an ini file:

[mypy]
exclude = generated

Well, of course it's a crutch. I do not pretend that this is the most correct way.

like image 31
Alexander Rakhmaev Avatar answered Oct 29 '22 19:10

Alexander Rakhmaev