type annotation for `{dict_keys,dict_items}.is_disjoint` argument is too narrow
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 5.1k
- Forks
- 2.1k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 82
Descripción
In the PR that added these annotations, @hauntsaninja said:
My instinct is to try it the stricter way and relax it if we ever get a real user complaint about it, but happy to go along with whatever others think is best
I'd like to provide such a complaint. In ty, we would like to infer precise key-type specializations (unions of string literals) of dict_keys and dict_items for closed TypedDicts, where all possible keys are known. We have real user requests for this, because it allows iterating over dict keys/items and passing the keys along to a function that expects a limited set of literals.
But doing this causes false positives with isdisjoint, because the following valid code will now error:
class TD(TypedDict, closed=True):
x: int
def check(td: TD) -> None:
# Both operations are safe at runtime but will report invalid-argument-type:
td.keys().isdisjoint(["other"])
td.items().isdisjoint([("other", 1)])
This is really a sub-issue of https://github.com/python/typeshed/issues/15271, the same category of issue as #6597.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza revisando las anotaciones introducidas en PR 12309 y la discusión relacionada en issue #15271. Reproduce los dos ejemplos de TypedDict cerrados de este issue y, después, ajusta la tipificación del argumento is_disjoint para que se acepten ambas llamadas válidas sin perder los tipos precisos de las claves y los elementos; verifica el comportamiento resultante de la comprobación de tipos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 58/100