E226: pycodestyle incorrectly warns about missing whitespace around operators

オープン
#658 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
tooling

調査の方向性

example.py スニペットと pycodestyle --select E226 を使って報告を再現します。まず pycodestyle の E226 実装を見つけ、リストスライス内の演算子をどのように処理しているかを確認します。通常の、2+2 のように空白を入れない算術式では引き続き警告が出る一方で、報告されたスライス内の + では警告が出ないことが完了条件です。

索引モデルが issue の本文から書いたものです。

説明

Given the following example.py,

my_list = [1, 2, 3]
a = 2+2
b = my_list[1:1+1]

pycodestyle incorrectly warns about the missing whitespace for the + operator inside the list slice:

» pycodestyle --select E226 ./example.py
./example.py:2:6: E226 missing whitespace around arithmetic operator  # OK
./example.py:3:16: E226 missing whitespace around arithmetic operator  # incorrect

The first warning (line 2) is correct (line 2 should read a = 2 + 2); the second warning (line 3) is incorrect according to PEP-8:

Yes:

ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
ham[lower:upper], ham[lower:upper:], ham[lower::step]
ham[lower+offset : upper+offset]
ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
ham[lower + offset : upper + offset]

No:

ham[lower + offset:upper + offset]
ham[1: 9], ham[1 :9], ham[1:9 :3]
ham[lower : : upper]
ham[ : upper]

Edit: okay, I'm not so sure I've got it 100%. The style I think is PEP-8 doesn't really seem to get listed anywhere, but even if I add spaces around the : (which is listed), I still get lints.

主要言語
Python
スター
5.2k
フォーク
765
平均マージ
1日 20時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PyCQA/pycodestyle のほかの issue

PyCQA/pycodestyle の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。