Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,011 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
tooling

Hướng nghiên cứu

Lưu các ví dụ được cung cấp dưới dạng bug.py và chạy pycodestyle --select=E306 --show-source bug.py để tái hiện hai false positive. Đọc entry point của bộ kiểm tra E306 trong tệp Python duy nhất của dự án, sau đó xác minh rằng các định nghĩa lồng nhau đứng trước bởi comment và dòng trống không còn báo cáo E306, trong khi các trường hợp hiện có vẫn giữ nguyên hành vi mong đợi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

$ 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!

Ngôn ngữ chính
Python
Star
5.2k
Fork
760
Merge trung bình
8 giờ 11 phút
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PyCQA/pycodestyle

Tất cả issue của PyCQA/pycodestyle

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.