Add `--warn-needless-override` option to `stubtest`

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

@sobolevn đang làm issue này rồi.

Từ ngày 4/8/2022.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

feature topic-stubtest

Feature

Imagine this file with implementation:

class A:
   def do_some(self) -> None:
       print('A')

class B(A):
   def do_some(self) -> None:
       print('B')

Auto-stub creators will create a stub like:

class A:
   def do_some(self) -> None: ...

class B(A):
   def do_some(self) -> None: ...

Which technically is right, but not quite.
Since do_some has the same signature in both A and B (only runtime implementation is different), we don't actually need it to be duplicated. We should ideally want just:

class A:
   def do_some(self) -> None: ...

class B(A): ...

Because we always want minimal correct stubs.
But, right now we only do this by hand.

Pitch

I propose adding --warn-needless-override options (with whatever name) that can warn us about needless overrides of parent methods in child classes.

I will send a PR with the initial imlementation.

Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
54

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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 python/mypy

Tất cả issue của python/mypy

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.