False negative when assigning generic function without parameter default to callback protocol

Aperta
#5,713 1 commento 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
40/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, rust
Ambito
devtools

Direzione di ricerca

Start by running the snippet in the issue: a generic impl[T] without a default on name is wrongly accepted for the Proto callback protocol. Compare it with the same function without the type variable, which pyrefly already rejects correctly, to find where generic signatures are handled differently during assignability. Done when fn: Proto = impl is reported as an error and the non-generic behaviour is unchanged.

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

Descrizione

typechecking
Describe the Bug

In the example below, impl should not be assignable to Proto, because name lacks a default value.

Removing the type-variable makes pyrefly behave as expected. [^1]

from typing import Any, Protocol

class Proto(Protocol):
    def __call__(self, arg: Any, name: str = ...) -> None: ...

def impl[T](arg: T, name: str) -> None: ...

fn: Proto = impl  # ❌️ False Negative
fn(1)  # TypeError at runtime (missing name)
Sandbox Link

https://pyrefly.org/sandbox/?project=v2.lZQ9jsIwEIWvMto03ibWFtvkAJSIAiqgMBCCJZKg2EEgxA2QOAH34DxcgCvwPMbhV0iU_pnxeOZ771vLDL52kxPviLAfAPKyGqNnjaxYCpzEzZmlii_FcXyjxK2CDPDqvN8dCg7r3gW9Xp8WiS8D-VwYUUSnw-583FNLgVnYc6ZcA9xV8ffrzhtsSVmq6sLqPCWRawNZZPwYIEIfa6vnxvckoh4W2q4bibItsWbLKlew6zofpZVYJUDT6x31BpC8nKaDnzbfSmiz2l5H-QRSRB2_QdeZwEJBYFbDqPEq_hzBo1OaWbswiZQhvKwymRZyUo6NfIiQrkBSS6XZ_h_TUcngG6R9T_A_V_mJogs

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