Improve "override" error output
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
(Opening a new issue for this as discussed in #12390.)
Live demo: https://mypy-play.net/?mypy=latest&python=3.10&flags=strict&gist=d3e1a06857e4c6f1c698b7fa89e22f40
Example code:
import typing as t
class A:
@t.overload
def pop(self) -> int: ...
@t.overload
def pop(self, d: int = ...) -> int: ...
def pop(self, d: int = ...) -> int: ...
class B(A):
@t.overload
def pop(self) -> int: ...
@t.overload
def pop(self, d: int) -> int: ...
def pop(self, d: int = ...) -> int: ...
Current mypy output:
main.py:14: error: Signature of "pop" incompatible with supertype "A"
main.py:14: note: Superclass:
main.py:14: note: @overload
main.py:14: note: def pop(self) -> int
main.py:14: note: @overload
main.py:14: note: def pop(self, d: int = ...) -> int
main.py:14: note: Subclass:
main.py:14: note: @overload
main.py:14: note: def pop(self) -> int
main.py:14: note: @overload
main.py:14: note: def pop(self, d: int) -> int
Found 1 error in 1 file (checked 1 source file)
It's somewhat helpful that mypy quotes the code in this error output, but it would be really helpful if mypy's output helped us zero in on exactly where the problem is, e.g.:
main.py:14: error: Signature of "pop" incompatible with supertype "A" in second overload
main.py:14: note: Superclass:
main.py:14: note: @overload
main.py:14: note: def pop(self) -> int
main.py:14: note: @overload
main.py:14: note: def pop(self, d: int = ...) -> int
^^^^^
main.py:14: note: Subclass:
main.py:14: note: @overload
main.py:14: note: def pop(self) -> int
main.py:14: note: @overload
main.py:14: note: def pop(self, d: int) -> int
Found 1 error in 1 file (checked 1 source file)
Note the addition of "in second overload" in the error message, as well as the all-important ^ arrows pointing to exactly where the supertype differs (namely, d should be a keyword argument). Without the arrows, it's harder to see in the output that the only difference is the = ... in the code for the superclass.
This is exacerbated when method signatures are more complex than this, e.g. MutableMapping.pop(), where the current output makes it even harder to spot where the problem is compared to this minimized example (see https://github.com/python/mypy/issues/12390#issuecomment-1073811096). It is also exacerbated by mypy ignoring the signature in the actual implementation, where d correctly appears as a keyword argument in the subclass. Finally, it can be exacerbated when upgrading to a mypy version that includes typeshed changes like this one: https://github.com/python/typeshed/pull/6941/commits/92438dcbe3e9e7720d9de56c6be0f0b5d2b14a2e#diff-b12c4be0f8e39f89957bbe7be6b6327185e18b69ea80a0f62c0746bb26f4a58eL478
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với bản demo trực tiếp của mypy-play và ví dụ overload A/B được cung cấp để tái hiện chẩn đoán hiện tại. Theo dõi chẩn đoán chữ ký override và các bài kiểm thử định dạng của nó; được xem là hoàn thành khi đầu ra xác định overload khác biệt, chỉ ra điểm không khớp và giữ nguyên ngữ cảnh so sánh hiện có.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- compilers
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 28/100