LoginSignup
10
7

More than 3 years have passed since last update.

【pylint】 出力結果の警告についての備忘録

Last updated at Posted at 2019-06-02

pylintというPythonのファイル整形モジュールを使うと、いろんな警告がでがちですが、それを ~/.pylintrc を編集して消す方法の備忘録

警告が出ても別にファイル自体の実行はできるけど鬱陶しいので消したい...

モジュール(module)とは

Python インタプリタを終了させ、再び起動すると、これまでに行ってきた定義 (関数や変数) は失われてしまうため、より長いプログラムを書きたい場合、Python では定義をファイルに書いておき、スクリプトの中やインタプリタの対話インスタンス上で使う方法があります。このファイルを モジュール (module) と呼び、APIドキュメントの生成にも利用可能です。

警告と回避法をいくつか紹介

Missing module docstring pylint(missing-docstring)

moduleに関する記述がないと言われています。
上記のエラーが出たら、disabled = missing-docstringを追加
この警告は、関数においても同様に出てしまうので、鬱陶しい。

因みに、下記のように説明文を加えて、警告を消すこともできます。

sample.py
def function():
    """functionの説明文
    説明文2行目
    説明文3行目
    説明文4行目
    """

Import "from sklearn.svm import [module名]" should be placed at the top of the module pylint(wrong-import-position)

importはファイルの先頭にまとめて書きましょうと言われています。
関数の中でimportすると、関数を呼ぶたびにimport処理が実行されます。
モジュールは結局1度だけしかオブジェクト生成されませんが、無駄な処理です。
moduleを変な位置でimportしていると、出る警告。
disabled = wrong-import-positionを追加すると消える。

Variable name "[変数名]" doesn't conform to snake_case naming style pylint(invalid-name)

グローバル変数に、"_"を付けないと出る警告。

Constant name "learn_data" doesn't conform to UPPER_CASE naming style pylint(invalid-name)

変数が大文字でないと出る警告。
disabled = invalid-nameを追加すると消える。
Constant name "learn_data" doesn't conform to UPPER_CASE naming style pylint(invalid-name)

結論

どうやら警告の最後の()内を~/.pylintrcのdisabledに追加すれば、その警告は消えてくれるらしい。

参照

[pylint ドキュメント]
https://buildmedia.readthedocs.org/media/pdf/pylint/latest/pylint.pdf

10
7
3

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
10
7