overload with wrong return type is ignored
Chưa có ai nhận issue này.
- 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
Mô tả
Bug Report
When one of the alternatives of an overload has a return type T which is a subtype of the return type of the annotation U but that the body of the function returns a type V which is a subtype of U but not T, no error is reported
To Reproduce
from typing import overload
@overload
def f(a: int) -> str:
...
# this is completely wrong
@overload
def f(a: str) -> bool:
...
def f(a: str | int) -> str | bool:
return "Hello"
reveal_type(f("some string"))
https://mypy-play.net/?mypy=latest&python=3.12&flags=strict&gist=83c5a353e087d8bbe03d542e7340b4b5
Expected Behavior
mypy should complain that the body of the function returns an str which is incompatible with type bool (overload 2)
More generally, for each overload signature, mypy should check that the body of the function typechecks with the overload signature.
Actual Behavior
mypy reports no error
main.py:16: note: Revealed type is "builtins.bool"
Success: no issues found in 1 source file
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 Python reproducer được hiển thị trong main.py và chạy nó với cấu hình strict mypy-play được liên kết. Theo dõi cách các chữ ký overload được kiểm tra so với kiểu trả về của phần triển khai. Hoàn tất khi mypy báo cáo giá trị trả về str không tương thích cho overload 2 và hồi quy được bao phủ bởi một test.
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
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- 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
- 38/100