[v1.5 regression] Repeating a type guard condition causes the guard to be lost

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

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

評価

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

調査の方向性

The report provides a Python example where repeating a TypeGuard condition with or loses the guard and causes two false positives. Start by reading the type checker’s handling of TypeGuard narrowing and boolean or expressions, then look for tests covering repeated guards. Done means the reported example preserves the narrowed type and no longer emits the false-positive diagnostics.

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

説明

typechecking
Describe the Bug

Reported impact: 2 false-positive diagnostics in the attrs library

from typing import Any, TypeGuard

class C(Any):
    pass

def has(cls: type) -> TypeGuard[type[C]]:
    return hasattr(cls, "tag")

def f(t: type[object]) -> None:
    if has(t) or has(t):
        reveal_type(t)
        t.tag  # object has no class attribute `tag`
Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pZQxD4IwEIX_ykUGGIzdXRlc3YGEigRIDDX08Pf7rmcxaEJi3Ejbd6V333u_RqZM-zTbKfhd_ZRn2IngaFMV5N76rLnBhBJNAYVFXchSkVdV7LKyBoVlnkS1x2PZduUujDz4ImMtVSj41SddYEiuhNEAiH6tcF5iEhvvdT7gGqIk-gxCGh3p2-RvhsvMLdU4VX_PPKGzLtCrfUg7wNLNyFRAcCjHBHHaUs9890djotxNnWlHc3WNNyuFIcHbPuwQknpdjlxg1KPsP7Clylq6hVoqpOHEJj1P

(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 を短くまとめたダイジェスト。