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

オープン
#5,701 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
53/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python, rust

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
7.2k
フォーク
578
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

facebook/pyrefly のほかの issue

facebook/pyrefly の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。