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

Aperta
#5,546 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python, rust

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Rust
Stelle
7.2k
Fork
578
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di facebook/pyrefly

Tutte le issue di facebook/pyrefly

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.