Overloaded generic constructors can cause spurious errors in class methods
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ả
This fails, while it shouldn't:
from typing import TypeVar, Generic, overload
T = TypeVar('T')
class C(Generic[T]):
@overload
def __new__(cls) -> C[None]: ...
@overload
def __new__(cls, item: T) -> C[T]: ...
def __new__(cls, item=None):
...
@classmethod
def f(cls, x: T) -> T:
return x
C.f(42) # Argument 1 to "f" of "C" has incompatible type "int"; expected "None"
I think the same also will happen with __init__(). The problem is because the return type of the first overload is always passed as an instance type to analyze_class_attribute_access().
Note: enabling test case testGenericClassInGenericFunctionOverloadedConstructor is blocked on this.
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 tại analyze_class_attribute_access() và tái hiện trường hợp hàm khởi tạo generic bị overload được nêu trong issue. Điều tra lý do kiểu trả về của overload đầu tiên được sử dụng làm kiểu của instance, sau đó kiểm tra hành vi init liên quan. Bật testGenericClassInGenericFunctionOverloadedConstructor và xác nhận rằng lỗi class-method không chính đáng không còn xảy ra.
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
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100