Overload validation does not properly handle implied subtype relationships (e.g. int and float)

Đang mở
#10,143 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
devtools

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện bốn ví dụ overload từ issue và so sánh các chẩn đoán của mypy với typing specification được liên kết. Tiếp theo, lần theo đường dẫn xác thực overload chịu trách nhiệm cho các kiểm tra chồng lấp subtype, rồi xác minh rằng trường hợp int/float được chẩn đoán nhất quán với các trường hợp literal, subclass và union.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug topic-overloads

I'm working to make pyright's overload validation work consistently with mypy's.

Mypy's overload validation behavior is spec'ed here: https://github.com/python/typing/issues/253#issuecomment-389262904

As part of this validation, mypy reports errors when there is overlap between two overloads that return different return types. The following test case shows four such examples. Mypy properly reports the error in three of the four cases, but it misses the case where there is an implied subtype relationship, as between int and float.

# pyright: strict

from typing import Literal, Union, overload

class Parent: ...
class Child(Parent): ...

# Test 1: Literal subtype
@overload
def foo1(x: Literal[3]) -> int: ...
@overload
def foo1(x: int) -> str: ...

# Test 2: Subclass subtype
@overload
def foo2(x: Child) -> str: ...
@overload
def foo2(x: Parent) -> int: ...

# Test 3: Implicit subtype
@overload
def foo3(x: int) -> str: ...  # Mypy does not report error here
@overload
def foo3(x: float) -> int: ...

# Test 4: Union subtype
@overload
def foo4(x: int) -> str: ...
@overload
def foo4(x: Union[int, str]) -> int: ...
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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.