Skip to content

Add grpc.experimental.gevent stubs#15839

Open
wangting0128 wants to merge 1 commit into
python:mainfrom
wangting0128:fix-grpcio-experimental-gevent
Open

Add grpc.experimental.gevent stubs#15839
wangting0128 wants to merge 1 commit into
python:mainfrom
wangting0128:fix-grpcio-experimental-gevent

Conversation

@wangting0128
Copy link
Copy Markdown

@wangting0128 wangting0128 commented May 27, 2026

Changes

Add a minimal stub for grpc.experimental.gevent, which exists in the grpcio runtime package but is currently missing from the partial grpcio stubs.

This adds:

  • stubs/grpcio/grpc/experimental/gevent.pyi

Follow-up to #15833.

Testing

python tests/runtests.py stubs/grpcio

Result:

--- TEST SUMMARY: All tests passed! ---

pre-commit Success
Check structure: Success
Pyright: Success
mypy: Success
stubtest: Skipped
Pyright regression tests: Success
mypy regression test: Success

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Collaborator

@brianschubert brianschubert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, see remarks below.

I'd normally be a little hesitant to add stubs for "experimental" APIs that may be removed in any minor release, but this particular function seems pretty stable (8+ yerars) and there seems to be ongoing work to maintain it / gevent compatibility, so adding it feels fine to me.

Comment on lines +1 to +5
from typing_extensions import assert_type

import grpc.experimental.gevent as grpc_gevent

assert_type(grpc_gevent.init_gevent(), None)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this file - test cases are only needed for weird and/or complicated cases that might regress in the future. This test basically repeats the signature (and a particularly trivial one at that :-)), so it isn't really necessary

@@ -0,0 +1 @@
from . import gevent as gevent
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime doesn't actually re-export gevent, so e.g. this fails:

$ uv run -w grpcio python3 -c 'import grpc.experimental; grpc.experimental.gevent'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import grpc.experimental; grpc.experimental.gevent
                              ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'grpc.experimental' has no attribute 'gevent'

Type checkers understand submodule relationships, so we don't need to add anything here in order for them to understand that the gevent submodule exists.

Suggested change
from . import gevent as gevent

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just delete this file, since partial-stub = true, and no direct members of this module are being stubbed. But if that ends up not being the case, you need to add the following to account for the fact that not all public functions are part of the stub file:

def __getattr__(name: str): ...  # incomplete module

The partial-stub marker in METADATA.toml only tells type checkers that whole modules are missing, not that modules that do exist might be incomplete. That's what the __getattr__ does. You may also need to add this module to pyrightconfig.stricter.json if not already covered

@wangting0128 wangting0128 force-pushed the fix-grpcio-experimental-gevent branch from 6dc375e to 406c809 Compare June 1, 2026 03:52
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@wangting0128
Copy link
Copy Markdown
Author

@brianschubert Thanks for the detailed review and the helpful explanation.

I’ve updated the PR based on your suggestions by removing the regression test and grpc/experimental/__init__.pyi, and keeping only grpc/experimental/gevent.pyi so the stub stays closer to the runtime behavior.

I’ve also updated the PR description to match the current changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants