Typing for callable inputs in itertools.starmap
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
Comienza leyendo la anotación de itertools.starmap en stdlib/itertools.pyi alrededor de las líneas 112-116 y, después, compárala con las sobrecargas de callable para map en stdlib/builtins.pyi alrededor de las líneas 1629-1670. Determina si la relación solicitada entre callable y los argumentos de entrada se puede expresar con el tipado actual de Python, y define qué debería garantizar una anotación correcta.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
The type annotations for itertools.starmap allow any iterables for any function arguments:
https://github.com/python/typeshed/blob/11c7821a79a8ab7e1982f3ab506db16f1c4a22a9/stdlib/itertools.pyi#L112-L116
This means I can do something like:
def myfunc(x: int, y: int):
return x + y
itertools.starmap(myfunc, [["foo, "bar"]])
and type checkers won't complain.
map gets around this to some extent with overloads for callables with up to 5 arguments (but if you need 6 or more, you're out of luck!)
https://github.com/python/typeshed/blob/11c7821a79a8ab7e1982f3ab506db16f1c4a22a9/stdlib/builtins.pyi#L1629-L1670
I couldn't figure out a way to ge that to work with starmap, though, because as far as I can tell the python type system doesn't have any way of specifying an iterable that returns a particular sequence of types. The best you can do is something like def __new__(cls, function: Callable[[_T1, _T2], T], iterable: Iterable[Iterable[_T1 | _T2]], /), which is still better in my opinion (it prevents invalid argument types), but it doesn't stop you from swapping function arguments.
Is there a way to do this? Or does it just need a new language feature? It would be great if we could do something like
P = ParamSpec("P")
def __new__(cls, function: Callable[P, T], iterable: Iterable[P.args], /)
- Lenguaje dominante
- Python
- Estrellas
- 5.1k
- Forks
- 2.1k
- Merge medio
- 2 d 1 h
- PR fusionados (30 d)
- 115
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la 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.
Más de python/typeshed
-
`networkx.set_edge_attributes` should support scalar value + namePosiblemente ocupada @Fire162 la tomó hace 10 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
Los mantenedores suelen responder en 1 día
-
false alarm on decode callPosiblemente ocupada @jw9829 la tomó hace 38 días. Abiertohelp wanted stubs: false positive
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
python/typeshed#16441 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Don't run pyright basic checks on projects with strict pyright settings in CIPosiblemente ocupada @Mohith1612 la tomó hace 74 días. Abiertoproject: infrastructure
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
python/typeshed#16005 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
stubs: improvement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python/typeshed#15548 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
stubs: improvement
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
python/typeshed#15529 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de python/typeshed
Issues similares
-
DBFS append mode silently overwrites existing filesPosiblemente ocupada @IlyaKhalafi la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
fsspec/filesystem_spec#2429 ·
Los mantenedores suelen responder en 1 día
-
[Bug]: Retrieval rerank fallback statistics stay zero after provider failurePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
volcengine/OpenViking#7014 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
fedora-copr/copr#4600 ·
Los mantenedores suelen responder en 2 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ansys/pydpf-core#3620 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día