Problem
grpc.experimental.gevent exists in the grpcio runtime package, but it is missing from the grpcio stubs in typeshed.
This causes type checkers and IDEs that consume typeshed stubs, such as types-grpcio or bundled typeshed stubs, to report grpc.experimental.gevent as an unresolved import even though the import works at runtime.
Reproduction
python -m venv .venv
source .venv/bin/activate
python -m pip install -U pip mypy grpcio gevent types-grpcio
cat > repro.py <<'PY'
import grpc.experimental.gevent as grpc_gevent
grpc_gevent.init_gevent()
PY
python repro.py
python -m mypy repro.py
Runtime succeeds:
But mypy reports:
repro.py:1: error: Cannot find implementation or library stub for module named "grpc.experimental.gevent" [import-not-found]
Runtime evidence
The module exists in grpcio:
grpc/experimental/gevent.py
For example, it is present in the upstream grpc repository at:
https://github.com/grpc/grpc/blob/v1.11.0/src/python/grpcio/grpc/experimental/gevent.py
The API currently exposed by that module is:
Current stub state
The current grpcio stubs in typeshed include:
stubs/grpcio/grpc/__init__.pyi
stubs/grpcio/grpc/aio/__init__.pyi
but there is no stub for:
stubs/grpcio/grpc/experimental/__init__.pyi
stubs/grpcio/grpc/experimental/gevent.pyi
Current directory:
https://github.com/python/typeshed/tree/main/stubs/grpcio/grpc
Proposed fix
Add:
stubs/grpcio/grpc/experimental/__init__.pyi
stubs/grpcio/grpc/experimental/gevent.pyi
with minimal contents:
# stubs/grpcio/grpc/experimental/__init__.pyi
from . import gevent as gevent
# stubs/grpcio/grpc/experimental/gevent.pyi
def init_gevent() -> None: ...
A regression test could also be added under:
stubs/grpcio/@tests/test_cases/check_experimental.py
with:
import grpc.experimental.gevent as grpc_gevent
grpc_gevent.init_gevent()
Problem
grpc.experimental.geventexists in thegrpcioruntime package, but it is missing from thegrpciostubs in typeshed.This causes type checkers and IDEs that consume typeshed stubs, such as
types-grpcioor bundled typeshed stubs, to reportgrpc.experimental.geventas an unresolved import even though the import works at runtime.Reproduction
Runtime succeeds:
But mypy reports:
Runtime evidence
The module exists in
grpcio:For example, it is present in the upstream grpc repository at:
https://github.com/grpc/grpc/blob/v1.11.0/src/python/grpcio/grpc/experimental/gevent.py
The API currently exposed by that module is:
Current stub state
The current
grpciostubs in typeshed include:but there is no stub for:
Current directory:
https://github.com/python/typeshed/tree/main/stubs/grpcio/grpc
Proposed fix
Add:
with minimal contents:
A regression test could also be added under:
with: