Ignore mypy errors from site-packages imports
Mypy by default silences all errors that come from installed third party packages in site-packages. This can be disabled with the --no-silence-site-packages flag.
However, they are not silenced in pytest-mypy-plugins tests and I don't see a way to enable that behavior.
For example in https://github.com/typeddjango/djangorestframework-stubs/pull/480 I enabled disallow_untyped_defs and disallow_incomplete_defs options, but then I got mypy errors from yaml-stubs package:
_________________________________________________________________________________________________ test_override_get_permissions _________________________________________________________________________________________________
/Users/marti.raudsepp/own/djangorestframework-stubs/tests/typecheck/test_views.yml:69:
E pytest_mypy_plugins.utils.TypecheckAssertionError: Output is not expected:
E Actual:
E ../../../../../../[...]/djangorestframework-stubs/.venv/lib/python3.11/site-packages/yaml-stubs/__init__.pyi:29: error: Function is missing a type annotation (diff)
E ../../../../../../[...]/djangorestframework-stubs/.venv/lib/python3.11/site-packages/yaml-stubs/__init__.pyi:30: error: Function is missing a return type annotation (diff)
... lots more ...
As a work-around, I can just suppress these in mypy.ini
[mypy-yaml.*]
disallow_untyped_defs = false
disallow_incomplete_defs = false
Passing the option --mypy-only-local-stub fixes this issue, eg:
pytest --mypy-only-local-stub tests/mypy/
I would argue this behavior should be the default. It's more useful and it's the default in Mypy, after all.
Should the pytest --mypy-only-local-stub be mentioned in CONTRIBUTING.md? Or the flag defined in pytest.ini/mypy.ini?