Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

E306: False positive when preceded by 2 blank lines and a comment

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
tooling

調査の方向性

提示された例を bug.py として保存し、pycodestyle --select=E306 --show-source bug.py を実行して、2 件の誤検知を再現します。プロジェクト唯一の Python ファイルにある E306 checker のエントリーポイントを読み、コメントと空行が前にあるネストされた定義で E306 が報告されなくなっていることを確認します。同時に、既存のケースが期待どおりの動作を維持していることも確認します。

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

説明

$ pycodestyle --version
2.7.0

If you have two blank lines, a comment, and then a nested function, E306 is raised erroneously.
(Since this false positive requires a genuine violation of E303, I don't think it's a big deal. But I noticed it, so I'm reporting it.)

The following functions both trigger false postives for E306.

def bad():
    _ = None


    # arbitrary comment

    def inner():  # E306 not expected (but happening! 1/2)
        pass
def bad():
    _ = None


    # arbitrary comment
    def inner():  # E306 not expected (but happening! 2/2)
        pass

For context, this snippet contains the false positives as well as cases that don't trigger E306:

def bad():
    _ = None


    # arbitrary comment

    def inner():  # E306 not expected (but happening! 1/2)
        pass


def bad():
    _ = None


    # arbitrary comment
    def inner():  # E306 not expected (but happening! 2/2)
        pass


def good():
    _ = None
    # arbitrary comment


    def inner():  # E306 not expected
        pass


def good():
    _ = None

    # arbitrary comment
    def inner():  # E306 not expected
        pass


def good():
    _ = None

    # arbitrary comment

    def inner():  # E306 not expected
        pass

If you dump that to a file (e.g., bug.py) and run pycodestyle on it, you'll get E306 inside the two bad() functions:

$ pycodestyle --select=E306 --show-source bug.py
bug.py:7:5: E306 expected 1 blank line before a nested definition, found 0
    def inner():  # E306 not expected (but happening! 1/2)
    ^
bug.py:16:5: E306 expected 1 blank line before a nested definition, found 0
    def inner():  # E306 not expected (but happening! 2/2)
    ^

Let me know if there's anything I can clarify/provide, thanks!

主要言語
Python
スター
5.2k
フォーク
760
平均マージ
8時間 11分
マージ済み PR(30日)
4

環境構築

はじめの一歩

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

PyCQA/pycodestyle のほかの issue

PyCQA/pycodestyle の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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