Mypy can't correctly infer nested union types in some situations
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start by running the issue's good, bad, and good2 examples with mypy and compare the inferred types for the list literal and concatenation. Trace the nested union and list inference path, then add a regression test showing that bad() is accepted without the cast while existing type-checking behavior remains intact.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I'm not sure what the cause is here, but I documented some simple examples of this issue. I would expect all of these examples to pass the type checker, but one fails peculiarly. I wouldn't be surprised if this is the result of an existing issue, but I couldn't find it.
from typing import cast, List, Union
Scalar = Union[str, float]
def good() -> List[Scalar]:
return ["foo", 1.0]
def bad(params: List[Scalar]) -> List[Scalar]:
# error: Incompatible return value type (got List[object], expected
# List[Union[str, float]])
# error: Unsupported operand types for + (List[object] and
# List[Union[str, float]])
return ["foo", 1.0] + params
def good2(params: List[Scalar]) -> List[Scalar]:
return cast(List[Scalar], ["foo", 1.0]) + params
- 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
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.
Issue khác của python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Issue tương tự
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
bancolombia/sentinel#23 ·
-
test md Đang mởCI
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100