1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【VSCode】【mypy】パッケージをimportすると発生するエラーを無視する

Last updated at Posted at 2021-06-25

問題

自作パッケージ等を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を設定すれば解決できると考えた。
しかし、この方法では解決できなかった。
mypyArgs.PNG

環境

mypy 0.910
VSCode バージョン: 1.57.1
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?