How to inherit argument types from a specific wrapped function
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
It would be great if there were a way to inherit the (argument) type signatures from one function to another. The use case here is something like:
def foo(
something: str,
*args: *requests.get.args,
**kwargs: **requests.get.kwargs
):
print(something)
return requests.get(*args, **kwargs)
I've found https://github.com/python/mypy/issues/2003, though that was closed a while back. I'm not totally clear why that was closed (from the comments I can't work out what the solution was, nor if agreement was reached on an approach). Additionally a lot has changed since then with regards to argument typing -- notably ParamSpec, TypeVarTuple & Unpack now exist, though I'm not sure if any of them actually help here as the wrapped function is static rather than also being part of the call signature.
Ideally I'd like to be able to do this in cases where the original function is annotated, though without needing to change that function's annotations (e.g: because it's in a library), so using e.g: Unpack[TypedDict] would require me to repeat the definitions of the original function's signature, which is partly what I'm trying to avoid by using passthrough *args, **kwargs in the first place.
Aside: is "inherit" the right term for this? I wasn't sure what to search for.
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 la sintaxis propuesta en este issue y la discusión previa en mypy issue #2003. Compara si ParamSpec, TypeVarTuple o Unpack permiten heredar anotaciones de una función envuelta estáticamente como requests.get; para darlo por hecho sería necesario un diseño acordado y un comportamiento documentado del comprobador de tipos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100