`mypy` widens multiple type parameters even when only the first one is relevant
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
- 48/100
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện mypy-play được liên kết và so sánh kiểu được suy luận với kỳ vọng của assert_type. Tiếp theo, lần theo logic khớp overload và mở rộng tham số kiểu liên quan đến lệnh gọi add, rồi thêm một bài kiểm thử hồi quy cho thấy chỉ tham số không khớp được mở rộng, trong khi tham số EA dùng chung vẫn được giữ nguyên.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report
When there are two type parameters to widen, mypy widens both to Any, even when the matched overloads agree on the second parameter and only actually disagree on the first.
Related to #19952
To Reproduce
https://mypy-play.net/?gist=6ab5724e788384125e85da02ae0386d3
from collections.abc import Sequence
from typing import Any, Generic, Protocol, assert_type, overload
from typing_extensions import TypeVar
S1 = TypeVar("S1")
class EA: ...
A = TypeVar("A", bound=EA, default=EA, covariant=True)
S2 = TypeVar("S2", bound=EA)
S2_contra = TypeVar("S2_contra", bound=EA, contravariant=True)
class Supports_ProtoAdd(Protocol[S2_contra, S2]):
def _proto_add(self, other: S2_contra, /) -> "Ser2[S2, EA]": ...
class Ser2(Generic[S1, A]):
def _proto_add(self, other: Any, /) -> "Ser2[Any, EA]":
raise NotImplementedError
@overload
def __add__(
self: Supports_ProtoAdd[S2_contra, S2],
other: "S2_contra | Sequence[S2_contra]",
) -> "Ser2[S2]": ...
@overload
def __add__(self: "Ser2[bool, EA]", other: Sequence[Any]) -> "Ser2[int]": ...
def __add__(self, other: Any) -> Any:
raise NotImplementedError
def f(a2: "Ser2[Any, EA]", seq: "Sequence[Any]") -> None:
assert_type(a2 + seq, "Ser2[Any, EA]")
# error: Expression is of type "Ser2[Any, Any]", not "Ser2[Any, EA]" [assert-type]
Expected Behaviour
Error free, as is the case for pyright, pyrefly and ty
Actual Behaviour
main.py:24: error: Expression is of type "Ser2[Any, Any]", not "Ser2[bool, EA]" [assert-type]
Found 1 error in 1 file (checked 1 source file)
Your Environment*
mypy 2.3.1 (playground)
- 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ự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
please add to porn list Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
StevenBlack/hosts#3255 ·