[v1.5 regression] Invalid context-manager use goes unchecked

Aperta
#5,548 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

Start with the type-checking path that reports bad-context-manager for a with statement, then use the supplied Python example and sandbox link to reproduce the regression. Trace how a suppressed diagnostic affects context-manager error reporting. Done when the example reports the invalid context-manager use while the suppressed diagnostic behavior remains correct.

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

Descrizione

typechecking
Describe the Bug

Only affected one repository (four incorrectly removed diagnostics), but the cause is that a usually suppressed diagnostic causes us to discard valid context-manager errors, which seems bad.

from typing import Any, Generic, TypeVar

T = TypeVar("T")

class Envoy(Generic[T]):
    def __call__(self, *args: list[Any]) -> Any:
        return None

    def __getattr__(self, key: str) -> "Envoy[T] | T | Any":
        raise AttributeError(key)

def use(e: Envoy) -> None:
    with e:  # No longer reports bad-context-manager
        pass

use(Envoy())  # Raises TypeError
Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pZXNboMwEIRfZQUHSKXU9976BlXFreTggEWQWrvCS9q8fcZrA_lRIkU5IPHn2WX9zfBoZM65mLIr7EeFztJlWWdVnckuJbPZvTuUadVXtZkAi7ZrMNPZdi_wwORY1NoIPDi5RfKpUGdYMw-zFqYmWSAadSZdoDpMVOGA6IzVAvI7BPrtyJHmEhLyHaHA6E0JJ4rMJdN_Pe8IDylHvNq2R0gZso6-ne3MgJbD8DxtdbtunGXzz-sfbTWeLQ1EFAEH6sSJrVZB8DM05heLXTOX00e8QWn7kLaAtRuR6YDwtbY54tzQjvnXvyk1LXdDp4xVrWu8OluhKNhL73Uvf4pzOXLiEQ_ZZ2AvIuvFPdSLQDreuEvvEQ

(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.