Incorrect narrowing after `TypeIs[type[...]]` check

Đang mở
#5,701 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
53/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, rust
Lĩnh vực
devtools, testing-qa

Hướng nghiên cứu

Start by reproducing the narrowing behavior in the linked Pyrefly sandbox, then trace how custom TypeIs predicates narrow both branches in the Rust type checker. Compare the TypeIs[type[bytes]] example with the built-in issubclass example and find the relevant narrowing tests. Done means the else branch retains the appropriate type instead of becoming Never, with regression coverage for the example.

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

Mô tả

narrowing typechecking
Describe the Bug

narrowing with a custom -> TypeIs[type[Foo]] incorrectly narrows the else branch to Never:

from typing import TypeIs, reveal_type

def is_bytes(obj: object, /) -> TypeIs[type[bytes]]:
    return isinstance(obj, type) and issubclass(obj, bytes)

def check(cls: type, /) -> None:
    if is_bytes(cls):
        reveal_type(cls)  # type[bytes]
    else:
        reveal_type(cls)  # Never

def check2(cls: type, /) -> None:
    if issubclass(cls, bytes):
        reveal_type(cls)  # type[bytes]
    else:
        reveal_type(cls)  # type[Any]
Sandbox Link

https://pyrefly.org/sandbox/?project=v2.tVW7DoJAEPyVjTQUxktMbPgDG2NjpcQAIhB5GA4MxPjvzu0B4QjRWFjq7dzOsTOzP0SmGvQWdp_kjRp2Is9-i442JNkLdkmCx69hR1V-5CLX7T-tFthIiEAuVVfoG2RwImufTatPGM4SUE2DOAxudpDC5ToYdb-R3FjlHTPUmeIeHsFHRBbf0lGc1_sMhoPfYLT-Tml4FSr7V_2BG2Ow6FzIoa6SVOrRWnTAj6Rqh6ThdOXoKcrMw9apMz8s7caBw3RsIRrMoV1Pix1XOfRsXp0iJ36waK__oE5a2AQwUlRj36Dr6pRbWDUhxVV1l44QPbwoIxHm4lIEUhgIoQiS9_AS3mLmdVSwfyWunTfihll-MsMb

(Only applicable for extension issues) IDE Information

No response

Ngôn ngữ chính
Rust
Star
7.2k
Fork
578
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

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 facebook/pyrefly

Tất cả issue của facebook/pyrefly

Issue tương tự

Thêm issue về Rust

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.