jupyter-server / enterprise_gateway

A lightweight, multi-tenant, scalable and secure gateway that enables Jupyter Notebooks to share resources across distributed clusters such as Apache Spark, Kubernetes and others.
https://jupyter-enterprise-gateway.readthedocs.io/en/latest/
Other
620 stars 223 forks source link

Add type hints to kernels service #1140

Closed kevin-bates closed 2 years ago

kevin-bates commented 2 years ago

This PR adds type hints to the methods within the services/kernels modules.

One item I would like to discuss is the return value on async def methods. I added a return value of Awaitable[str] on the start_kernel method, but the other async methods (here and elsewhere in EG to the best of my knowledge) do not use the Awaitable type and I'm curious what others think.

The other thing I noticed is that my IDE (PyCharm) is hi-lighting kernel_id as an expected type of uuid.pyi where I've added str yet none of the dependent repositories (jupyter_server and jupyter_client) specify uuid.pyi as a type hint (few even specify str). I suspect this particular annotation is coming from the installed package area via the py.typed file (although it is zero-length), but I'm not sure. Does anyone know what might be happening there? I suspect its some kind of mypy thing that jupyter_server and jupyter_client are built with.

Fixes: #848

kevin-bates commented 2 years ago

One item I would like to discuss is the return value on async def methods.

Regarding my question regarding how to type-hint the return type of async def methods, it looks like -> Awaitable[return-type]: should really just be ->return-type: per https://mypy.readthedocs.io/en/stable/more_types.html#typing-async-await, so I'm going to make another commit that updates this occurrence to str and addresses the CodeQL issue that also exists.