False positive in `dict.update` with variadic tuple keys

Abierto
#5,712 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start by running the four-line snippet in the issue (the d.update({(*prefix, 0, n): 1 ...}) case) against a local build to reproduce the no-matching-overload error. The payload does not name the source files, so locate the contextual inference for dict comprehensions and the handling of variadic tuple keys. Done means the snippet type-checks cleanly with no new errors in the existing test suite.

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

Descripción

typechecking
Describe the Bug

Actual: no-matching-overload

The comprehension is inferred as dict[tuple[*tuple[int, ...], int, str], int], and dict[tuple[*tuple[int, ...], int, str], int] cannot be assigned to SupportsKeysAndGetItem[tuple[*tuple[int, ...], str], int] (this protocol is invariant in the key type).

Expected: Contextual inference should allow the comprehension to be typed as dict[Key, int]. ty 0.0.107 accepts this example.

type Key = tuple[*tuple[int, ...], str]
prefix: tuple[int, ...] = (1, 2, 3)
d: dict[Key, int] = {}
d.update({(*prefix, 0, n): 1 for n in ("train", "test")})
ERROR sandbox.py:4:9-58: No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[tuple[*tuple[int, ...], int, str], int]) [no-matching-overload]
  Possible overloads:
    (m: SupportsKeysAndGetItem[tuple[*tuple[int, ...], str], int], /) -> None [closest match]
    (m: Iterable[tuple[tuple[*tuple[int, ...], str], int]], /) -> None
  Argument `dict[tuple[*tuple[int, ...], int, str], int]` is not assignable to parameter `m` with type `SupportsKeysAndGetItem[tuple[*tuple[int, ...], str], int]` in function `typing.MutableMapping.update`
Sandbox Link

https://pyrefly.org/sandbox/?project=v2.fVTNysIwEHyVpb1ECcnnJ17yCoJ48WQ9VBu1oG1pE1FK393ppgqKegr52c3Ozux8s8zeTWhub_jUeUzLehwWdFiSUmrDcgGeCi3Ir2Z49bxGnJhI-pc0BRmZoQzutkZCCdZcf912OFe-wlBb0YpxSCTpT1IxMjShnmYQXJBIIgcagFuiAz2wJBp1SAuY3uWnJpQc0wqb3N2eE8SuwSNV1ucUburPW1sLVIsaWJvA8OA5qH2fRAt-Zai9dkOn33iOaRkOaGgZHA4COXj4KH5VSRHDQi0dnasao_UjvKwP2hY6K3eNfonQjDW9pDm782s6KlmXDdJ-FtiMq_xF8h0

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