Any is inferred with a certain combination of overloads and generics
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ả
Bug Report
(I couldn't come up with a better title, please fix)
I've got a piece of code where the inferred type is sometimes Any when it shouldn't be, and the difference between getting Any and the correct result doesn't make sense so it looks like a mypy bug to me. I may be wrong though.
The background: I'm trying to refactor and fix the overloads for https://github.com/scrapy/scrapy/blob/2b9e32f1ca491340148e6a1918d1df70443823e6/scrapy/utils/defer.py#L360, I've simplified the overloads and ignored the "overlapping signatures" error per https://stackoverflow.com/questions/60222982/type-annotation-for-overloads-that-exclude-types-something-vs-everything-else but the inferred result of the function works fine only if the input coroutine doesn't return e.g. List[Any]. It doesn't seem to fall back to the second overload either, as that wouldn't result in Any too. Overall it doesn't look like something with my code but maybe I'm missing something.
To Reproduce
https://gist.github.com/mypy-play/29b3eb14ab12db21dc8f52594f40c392
Expected Behavior
I expect the revealed type to always be a Deferred with the same param as the coroutine result type and never Any.
Actual Behavior
It's Any when, it looks like, the argument type has Any in it.
Your Environment
- Mypy version used: 1.10.0
- Python version used: 3.12
- Playground URL: https://mypy-play.net/?mypy=latest&python=3.12&gist=29b3eb14ab12db21dc8f52594f40c392
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 tái hiện mypy-play và gist được liên kết, so sánh việc phân giải overload và các kiểu được tiết lộ khi kết quả của coroutine chứa Any thay vì một kiểu chính xác. Kiểm tra hành vi trên mypy 1.10.0 và Python 3.12; được xem là hoàn tất khi kết quả được tiết lộ luôn giữ nguyên kiểu kết quả của coroutine thay vì trở thành Any.
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, 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
- 35/100