Skip to content
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

Ignore mypy errors from site-packages imports #134

Open
intgr opened this issue Oct 5, 2023 · 3 comments
Open

Ignore mypy errors from site-packages imports #134

intgr opened this issue Oct 5, 2023 · 3 comments

Comments

@intgr
Copy link

intgr commented Oct 5, 2023

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 typeddjango/djangorestframework-stubs#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
@bricker
Copy link

bricker commented Nov 19, 2023

Passing the option --mypy-only-local-stub fixes this issue, eg:

pytest --mypy-only-local-stub tests/mypy/

@Tinche
Copy link

Tinche commented Dec 16, 2023

I would argue this behavior should be the default. It's more useful and it's the default in Mypy, after all.

@SukiCZ
Copy link

SukiCZ commented Apr 25, 2024

Should the pytest --mypy-only-local-stub be mentioned in CONTRIBUTING.md? Or the flag defined in pytest.ini/mypy.ini?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants