`explicit-any-use`/`unknown-from-error` errors highlight the expression but the error message references the variable

Aperta
#5,710 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Search the Rust codebase for the diagnostic names explicit-any-use and unknown-from-error, then find where each diagnostic attaches its range and how the message gets the assigned variable name. Reproduce both snippets from the issue, or the sandbox, and compare the case where the result is not assigned. Done means the highlighted range and the message agree on whether the error is about the expression or the variable; add or update the relevant diagnostic test.

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

Descrizione

language-server
Describe the Bug
from typing import Any

def fn() -> Any: ...
def fn2() -> Unknown: ... # pyrefly: ignore[unknown-name]


foo = fn()
#     ^^^^ error: The type of `foo` is an explicit `Any`
foo = fn2()
#     ^^^^^ error: The type of `foo` is unknown because it comes from an error

the underlined code is the expression:

image

but the error messages refer to the variable foo.

this can be really confusing in some cases:

from typing import Any

def fn(foo: int) -> Any: ...


foo = fn(1)
#     ^^^^^ error: The type of `foo` is an explicit `Any`

here it looks like the error is talking about the function parameter called foo

idk whether the best fix is to change the range where the errors are reported or just change the error messages. i'm leaning towards the former, because the error goes away when the result is not assigned to a variable, indicating that the error is actually about the variable rather than the expression.

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.lVQxDsIwDPyKpc7NgJj6DpiQUELkCATEFVABv-fspAiWqs3oxJez7-xlK_Nr0SotQh0558boqoS3-Zzlme2KGqpt6qiUuBvKdaty21yivSZtY7ba41QJaHNkZcEkiXwS8WrvkIlf_eUU4SUPCl7z8fUvwDRCZUAHjmGAhwEU5YrlZmUrvibPVXitgvQ3vvPDQjDKv-Yj2zbkN16kgDmaVOUD

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