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

Abierto
#5,710 0 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python, rust
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Rust
Estrellas
7.2k
Forks
578
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de facebook/pyrefly

Todos los issues de facebook/pyrefly

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.