問題
自作パッケージ等をimportすると発生するエラーを無視したい。
from my_class import MyClass # Cannot find implementation or library stub for module named 'my_class'
# 実行できるのに、エラーが表示される
解決方法
作業環境にmypy.ini
を作成して、ignore-missing-imports = True
を設定する。
この時、セクションを[mypy-*.*]
とすることで、全てのモジュールに対して設定できる。
例
current_dir/
┗━.vscode/
┣━ settings.json
┗━ mypy.ini
settings.json
{
"mypy.configFile": ".vscode/mypy.ini",
}
mypy.ini
[mypy-*.*]
ignore_missing_imports = True
解決できなかった方法
本問題についてググると「mypyの実行引数に--ignore-missing-imports
を設定する」と出てくる。
VSCodeの設定の中にpython.linting.mypyArgs
があるので、ここに--ignore-missing-imports
を設定すれば解決できると考えた。
しかし、この方法では解決できなかった。
環境
mypy 0.910
VSCode バージョン: 1.57.1