Skip to content

grpcio: missing stub for grpc.experimental.gevent #15833

@wangting0128

Description

@wangting0128

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:

runtime ok

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:

def init_gevent():
    ...

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    stubs: incompleteAnnotations or sub-modules missing from an existing package or module
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions