Add ReturnType-like utility for getting function return types
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
This is a feature request, so if there is a way to achieve this already, please point me and future me in the right way.
In TypeScript, we can use the ReturnType utility type to get the return type of a function to reuse in other places. This is very useful to make the code short, readable, and easy to change if necessary, especially in cases where I want to wrap the call of a function from another module in some other function.
An example of how it might be used:
# module: foo.py
def foo() -> None | baz.Baz | tuple[int, int]:
...
# module: bar.py
def bar() -> ReturnType[foo.foo]:
...
In this case, I could maybe give the return type a name like FooReturn and import that in bar, but that seems less elegant rather than just reusing the function I'm already using.
Note that if automatic or manual type inference (https://github.com/python/mypy/issues/4409) was implemented, most of my usages would be covered.
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 utilidad similar a ReturnType solicitada en este issue y el issue #4409 de mypy enlazado sobre la inferencia de tipos automática o manual. Determina la sintaxis de tipos y el comportamiento previstos para el ejemplo de foo.py y bar.py; done debe significar que se admite la reutilización solicitada del tipo de retorno o que se documenta el enfoque compatible existente.
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
- 30/100