LoginSignup
2
5

More than 3 years have passed since last update.

Python お作法

Last updated at Posted at 2018-11-09

2019-07 現在の自分の Python の使い方を記録。参考資料:

選択したツール

  • 整形ツール
    • black
    • 理由: 設定項目が少ないらしいので
    • 実行方法: black ディレクトリ
  • 型チェック
    • mypy
    • 理由: 標準なので
    • 実行方法: mypy ディレクトリ
    • 厳しい実行方法: mypy --disallow-untyped-defs sherpa
  • コード解析
    • pylint
    • 理由: たまたま VisualStudio Code のデフォルトだったので
    • 実行方法: pylint ディレクトリ
  • ドキュメント
    • pydoc ./ファイル名 でたまに docstring の見た目を確認

mypy

何もやってないと以下のようなエラーが大量に出る。

error: Cannot find module named 'folium'
error: No library stub file for module 'sklearn.preprocessing'
...

メジャーなライブラリには型が付いていたり
stub で型を付けられているが、そ
うでないやつは明示的に無視する。

[mypy]

[mypy-sklearn.*]
ignore_missing_imports = True

[mypy-numpy.*]
ignore_missing_imports = True

のようなファイルを mypy.ini として保存すると無視される。

VSCode の settings.json

    "[python]": {
        "editor.formatOnSave": true
    },
    "python.linting.mypyEnabled": true,
    "python.linting.pylintEnabled": true,
    "python.formatting.provider": "black",
    "python.linting.pylintArgs": ["--disable", "line-too-long,bad-continuation"]
    "python.linting.mypyArgs": ["--disallow-untyped-defs"],
2
5
2

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
2
5