False positive error "incompatible type" on bound TypeVar
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ả
Originally posted on gitter july 29th, where it was suggested I open a bug report
Bug Report
For this code:
from typing import Generic, TypeVar, Union
ListT = TypeVar("ListT", str, float)
class TestListA(Generic[ListT]):
def __init__(self, device: ListT) -> None:
self._device: ListT = device
class TestListB(TestListA[ListT]):
def __init__(self, device: ListT) -> None:
super().__init__(device)
mypy outputs error:
test.py:13: error: Argument 1 to "__init__" of "TestListA" has incompatible type "str"; expected "ListT" [arg-type]
test.py:13: error: Argument 1 to "__init__" of "TestListA" has incompatible type "float"; expected "ListT" [arg-type]
which is false positive.
Please note that when using a TypeVar with bound=Union, then mypy doesn't complain.
ListT = TypeVar("ListT", bound=Union[str, float])
Your Environment
- Mypy version used:
mypy 0.971 (compiled: yes) - Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used:
Python 3.9.12 - Operating system and version:
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 bằng cách tái hiện ví dụ TestVar được cung cấp với mypy 0.971, sau đó so sánh hành vi TypeVar bị ràng buộc của nó với biến thể bound=Union. Xác định đường dẫn kiểm tra kiểu cho TestListB.init và bổ sung phạm vi kiểm thử hồi quy cho các chẩn đoán dương tính giả. Được xem là hoàn tất khi ví dụ bị ràng buộc vượt qua mà không có lỗi, trong khi các lời gọi không tương thích vẫn được chẩn đoán.
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
- 38/100