Add grpc.experimental.gevent stubs#15839
Conversation
This comment has been minimized.
This comment has been minimized.
brianschubert
left a comment
There was a problem hiding this comment.
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.
| from typing_extensions import assert_type | ||
|
|
||
| import grpc.experimental.gevent as grpc_gevent | ||
|
|
||
| assert_type(grpc_gevent.init_gevent(), None) |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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.
| from . import gevent as gevent |
There was a problem hiding this comment.
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 moduleThe 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
6dc375e to
406c809
Compare
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
|
@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 I’ve also updated the PR description to match the current changes. |
Changes
Add a minimal stub for
grpc.experimental.gevent, which exists in thegrpcioruntime package but is currently missing from the partialgrpciostubs.This adds:
stubs/grpcio/grpc/experimental/gevent.pyiFollow-up to #15833.
Testing
Result: