mypy --exclude not working in settings.json

See original GitHub issue

Environment data

Version: 1.57.0 Commit: b4c1bd0a9b03c749ea011b06c6d2676c8091a70c Date: 2021-06-09T17:22:31.215Z Electron: 12.0.9 Chrome: 89.0.4389.128 Node.js: 14.16.0 V8: 8.9.255.25-electron.0 OS: Darwin x64 19.6.0

Name: Python Id: ms-python.python Version: 2021.6.944021595

Name: Pylance Id: ms-python.vscode-pylance Version: 2021.6.2

mypy 0.902

Expected behaviour

Setting "python.linting.mypyArgs": ["--exclude", "tests"] in settings.json disables mypy on the tests/ directory.

Actual behaviour

VSCode detects an error in files under tests/.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Install mypy
  2. Create a directory tests/
  3. Add a python file in there with a mypy error
  4. Set "python.linting.mypyArgs": ["--exclude", "tests"] in settings.json
  5. Open the file from step 4 and vscode will show a mypy error

When running mypy --exclude tests . in the terminal, mypy will not show an error

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
bluebrowncommented, Sep 25, 2021

The issue is that VS Code is invoking mypy file by file. And mypy doesn’t use the exclude option when invoked on a single file. The workaround is using python.linting.ignorePatterns in the settings.json.

 "python.linting.ignorePatterns": [ "tests/**/*.py" ]

More info about the behaviour of exclude:

Note that this flag only affects recursive discovery, that is, when mypy is discovering files within a directory tree or submodules of a package to check. If you pass a file or module explicitly it will still be checked. For instance, mypy --exclude ‘/setup.py$’ but_still_check/setup.py.

0reactions
speediedancommented, Mar 3, 2022

another workaround if you’d prefer to keep linting on in general for a set of files, but disable mypy only, would be to add an empty --exclude to python.linting.mypyArgs. Note there will be significant computational overhead with this approach though since this will result in all non-excluded files (via other configuration, pyproject.toml for instance) being checked for every file checked (every open file with modifications it seems). Any sense of when this bug is targeted for a fix? Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exclude folder from mypy checking - python - Stack Overflow
And mypy doesn't use the exclude option when invoked on a single file. The workaround is using python.linting.ignorePatterns in the settings.
Read more >
The mypy configuration file - mypy 0.991 documentation
Mypy supports reading configuration settings from a file. ... To refer to the user home directory, use ~ at the beginning of the...
Read more >
mypy — Debian unstable
py$' --exclude '/build/'. Note that this flag only affects recursive directory tree discovery, that is, when mypy is discovering files within a ...
Read more >
Mypy Documentation - Read the Docs
import json else: import orjson as json # mypy is unaware of this. In some cases type annotations can cause issues at runtime,...
Read more >
python/mypy - Gitter
it's the same as I can define an alias X = Tuple[T, T] no problem; but once I want to annotate a variable,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found