Document how to declare dependant types in method signatures
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
I have several TypedDict:
TerminateHandlerContextType = TypedDict( "TerminateHandlerContextType",{...},)
CrashHandlerContextType = TypedDict( "CrashHandlerContextType", {... },)
QuitHandlerContextType = TypedDict("QuitHandlerContextType", {...})
And then related Callable:
TerminateHandlerType = Callable[[TerminateHandlerContextType], None]
QuitHandlerType = Callable[[QuitHandlerContextType], None]
CrashHandlerType = Callable[[CrashHandlerContextType], None]
If I then declare a method that depends of both:
def _call_handler(
self,
handler: Union[
TerminateHandlerType, QuitHandlerType, CrashHandlerType
],
context: Union[
TerminateHandlerContextType, QuitHandlerContextType, CrashHandlerContextType,
],
):
...
return handler(context) # <---- MYPY COMPLAINS HERE
Then mypy complains, because, while I always ensure logically that the proper handler is called with the proper context, it can't see that.
I couldn't find in the documentation a way to tell it that the context type depends on the handler type. I assume it's either a Generic, or a TypeVar, but didn't find the solution.
mypy 0.770
python 3.6
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
En el issue no se nombra ningún archivo de documentación, prueba ni punto de entrada. Primero determina qué sección de la documentación de mypy cubre las relaciones dependientes entre los tipos del handler y del contexto, y después verifica el enfoque documentado con el ejemplo de TypedDict y Callable. Se considera terminado cuando la documentación explica cómo expresar o gestionar esta relación y aborda el problema de comprobación de tipos señalado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Documentación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 35/100