flake8-3.6.0 に更新したら警告たくさん出てきた
flake8 3.6.0 が2018/10/23にリリースされた その影響で、新しいflake8を使ったテスト(CI等)で警告がたくさん出てきた
flake8-3.6.0では、 pycodestyle==2.4.* が使われるようになった
pycodestyle-2.4.0 で、Warningが追加された
例 W605:
W605は文字列中の不正なエスケープシーケンスの検出。正規表現の文字列に r 付け忘れたりすると警告される
例 E252:
def func(arg: str='blah'): みたいな型指定をしてるとE252が出る
def func(arg: str = 'blah'): と書き直すと治まる
Add E252 error for missing whitespace around equal sign in type annotated function arguments with defaults values.
2. ignore上書き
flake8のオプションに --extend-ignore が追加された
その影響か、いままで警告されていなかったW503, W504等が警告されるようになった
flake8に--ignoreオプション指定してると、デフォルトのignoreを上書きする動作になったっぽい(推測)
tox.iniのflake8セクションにignore=を書いてる等
pycodestyleでは一部の警告をデフォルト無効にしてるけどignore上書きされると有効化されちゃう
W503, W504 について
In the default configuration, the checks E121, E123, E126, E133, E226, E241, E242, E704, W503, W504 and W505 are ignored because they are not rules unanimously accepted, and PEP 8 does not enforce them.
pycodestyleのデフォルトではこの警告は使わないよ (edited)
Please note that if the option –ignore=errors is used, the default configuration will be overridden and ignore only the check(s) you skip.
ignoreオプションを指定するとき、無視するエラーを上書きしちゃうので、これらの警告をoffのままにしたい人は注意してね
The check W503 is mutually exclusive with check W504.
W503, W504 は排他的な指摘なので両立しないよ
flake8のオプションを --ignore じゃなく --extend-ignore で指定すると解決できる
tox.iniの場合
code:tox.ini
extend-ignore=...
こうする場合は flake8>=3.6.0 を指定すること
3.5.x ではextend-ignoreオプションがない
3. import * # flake8: noqa がファイル全体じゃなくその行だけを対象とするようになった
from xxx import * # flake8: noqa 等のコードを書かざる得ないシーンがある
flake8-3.6以前は、ファイル全体にnoqaが効いてしまっていて、そのファイルはflake8でテストされてなかった 3.6からは、その行だけが対象になったので、flake8で他の行がちゃんとチェックされるようになった
Only skip a file if # flake8: noqa is on a line by itself (See also GitLab#453, GitLab!219)
がんばって、なおしましょう
ファイル先頭に # flake8: noqa: F403,F405を書くことで修正が楽になる