You can disable mypy error codes using the special comment # type: ignore[code, ...]
. E.g.:
def f(): # type: ignore[call-arg]
pass
To disable multiple codes in one line, simply separate the codes with a comma, e.g.:
def f(): # type: ignore[call-arg, arg-type]
pass
You can also configure the mypy.ini
configuration file directly to ignore specific error codes for the whole codebase. E.g.:
zsh> cat >> mypy.ini <<EOL
heredoc> [mypy]
heredoc> ignore_missing_imports = True
heredoc> EOL
More in this page: mypy.readthedocs.io/en/stable/config_file.html.
Note: it is never a good practice to deactivate the error messages mypy is raising. Always try to work on it. E.g. a too-many-arguments code on a method probably means that you are missing one intermediary method and should refactor your code.
Finally, mypy
checks usually come in pair with black
, pylint
and unitests
checks. You can combine error codes by-passing issued by multiple checkers on the same special inline comment:
@decorator() # type: ignore[call-arg, arg-type] # pylint: disable="no-value-for-parameter"
def f(): ...
More on how to disable pylint error checks: olivierbenard.fr/disable-pylint-error-checks.
Note: to know more about mypy error codes, you can visit mypy.readthedocs.io/en/stable/error_codes.html.