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

Mypy exclude doesn't work as expected #18284

Closed
artsiomkaltovich opened this issue Dec 12, 2024 · 1 comment
Closed

Mypy exclude doesn't work as expected #18284

artsiomkaltovich opened this issue Dec 12, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@artsiomkaltovich
Copy link

Bug Report

I want to exclude a folder from mypy checks, but it still inspect it.

mypy -v output:

LOG:  Mypy Version:           1.13.0
LOG:  Config File:            /Users/a_kaltovich/projects/mypy_doesnot_work/pyproject.toml
LOG:  Configured Executable:  /Users/a_kaltovich/projects/mypy_doesnot_work/.venv/bin/python
LOG:  Current Executable:     /Users/a_kaltovich/projects/mypy_doesnot_work/.venv/bin/python
LOG:  Cache Dir:              .mypy_cache
LOG:  Compiled:               True
LOG:  Exclude:                ['libs']

To Reproduce

Expected Behavior

libs folder is excluded

Actual Behavior

libs/lib1/lib1.py:2: error: Incompatible return value type (got "int", expected "str") [return-value]

Your Environment

Refer to pyproject.toml file.

@artsiomkaltovich artsiomkaltovich added the bug mypy got something wrong label Dec 12, 2024
@brianschubert
Copy link
Collaborator

Hi! This is expected behavior. The exclude option controls how mypy discovers files to type check (you can think of it as refining the "entry points" for type checking). However it doesn't affect the way that the discovered files are type checked. In particular, it doesn't affect the way mypy follow imports. If any of the files being analyzed import a module from libs, then by default that module will be analyzed as well (along with any modules that it imports). You can refer to Following Imports from the mypy docs for more details on how this works and what configuration options are available.

If you want to suppress errors for modules from libs, you can try setting follow_imports to silent for those modules:

[[tool.mypy.overrides]]
module = "libs.*"
follow_imports = "silent"

@brianschubert brianschubert closed this as not planned Won't fix, can't repro, duplicate, stale Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants