-
Notifications
You must be signed in to change notification settings - Fork 84
DRAFT Add flags to generate only sync or only async stubs #694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d946d68
9727cbf
52e18dd
ddd9a2f
28d2401
3298f4b
cb32bd6
c497b7d
82e6e75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """ | ||
| Type-checking test for async_only GRPC stubs. | ||
|
|
||
| This module is run through mypy to validate that stubs generated with the | ||
| only_async flag have the correct types: | ||
| - Regular (non-generic) Stub class that only accepts grpc.aio.Channel | ||
| - No AsyncStub type alias (the stub itself is async-only) | ||
| - Servicer methods use AsyncIterator for client streaming (not _MaybeAsyncIterator) | ||
| - add_XXXServicer_to_server accepts grpc.aio.Server | ||
| """ | ||
|
|
||
| from typing import Awaitable | ||
|
|
||
| import grpc.aio | ||
| from testproto.grpc import dummy_pb2, dummy_pb2_grpc | ||
|
Check warning on line 15 in test/async_only/test_async_only.py
|
||
|
|
||
|
|
||
| class AsyncOnlyServicer(dummy_pb2_grpc.DummyServiceServicer): | ||
| async def UnaryUnary( | ||
| self, | ||
| request: dummy_pb2.DummyRequest, | ||
| context: grpc.aio.ServicerContext[dummy_pb2.DummyRequest, Awaitable[dummy_pb2.DummyReply]], | ||
| ) -> dummy_pb2.DummyReply: | ||
| await context.abort(grpc.StatusCode.UNIMPLEMENTED, "Not implemented") | ||
| return dummy_pb2.DummyReply(value=request.value[::-1]) | ||
|
|
||
|
|
||
| async def noop() -> None: | ||
| """Don't actually run anything; this is just for type-checking.""" | ||
| stub = dummy_pb2_grpc.DummyServiceStub(channel=grpc.aio.insecure_channel("localhost:50051")) | ||
| await stub.UnaryUnary(dummy_pb2.DummyRequest(value="test")) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| """ | ||
| @generated by mypy-protobuf. Do not edit manually! | ||
| isort:skip_file | ||
| https://github.com/vmagamedov/grpclib/blob/master/tests/dummy.proto""" | ||
|
|
||
| import abc | ||
| import collections.abc | ||
| import grpc.aio | ||
| import sys | ||
| import testproto.grpc.dummy_pb2 | ||
| import typing | ||
|
|
||
| if sys.version_info >= (3, 10): | ||
| import typing as typing_extensions | ||
| else: | ||
| import typing_extensions | ||
|
|
||
| if sys.version_info >= (3, 13): | ||
| from warnings import deprecated | ||
| else: | ||
| from typing_extensions import deprecated | ||
|
|
||
|
|
||
| GRPC_GENERATED_VERSION: str | ||
| GRPC_VERSION: str | ||
| _DummyServiceUnaryUnaryType: typing_extensions.TypeAlias = grpc.aio.UnaryUnaryMultiCallable[ | ||
| testproto.grpc.dummy_pb2.DummyRequest, | ||
| testproto.grpc.dummy_pb2.DummyReply, | ||
| ] | ||
| _DummyServiceUnaryStreamType: typing_extensions.TypeAlias = grpc.aio.UnaryStreamMultiCallable[ | ||
| testproto.grpc.dummy_pb2.DummyRequest, | ||
| testproto.grpc.dummy_pb2.DummyReply, | ||
| ] | ||
| _DummyServiceStreamUnaryType: typing_extensions.TypeAlias = grpc.aio.StreamUnaryMultiCallable[ | ||
| testproto.grpc.dummy_pb2.DummyRequest, | ||
| testproto.grpc.dummy_pb2.DummyReply, | ||
| ] | ||
| _DummyServiceStreamStreamType: typing_extensions.TypeAlias = grpc.aio.StreamStreamMultiCallable[ | ||
| testproto.grpc.dummy_pb2.DummyRequest, | ||
| testproto.grpc.dummy_pb2.DummyReply, | ||
| ] | ||
| class DummyServiceStub: | ||
| """DummyService""" | ||
|
|
||
| def __init__(self, channel: grpc.aio.Channel) -> None: ... | ||
|
|
||
| UnaryUnary: _DummyServiceUnaryUnaryType | ||
| """UnaryUnary""" | ||
|
|
||
| UnaryStream: _DummyServiceUnaryStreamType | ||
| """UnaryStream""" | ||
|
|
||
| StreamUnary: _DummyServiceStreamUnaryType | ||
| """StreamUnary""" | ||
|
|
||
| StreamStream: _DummyServiceStreamStreamType | ||
| """StreamStream""" | ||
|
|
||
| class DummyServiceServicer(metaclass=abc.ABCMeta): | ||
| """DummyService""" | ||
|
|
||
| @abc.abstractmethod | ||
| def UnaryUnary( | ||
| self, | ||
| request: testproto.grpc.dummy_pb2.DummyRequest, | ||
| context: grpc.aio.ServicerContext[testproto.grpc.dummy_pb2.DummyRequest, collections.abc.Awaitable[testproto.grpc.dummy_pb2.DummyReply]], | ||
| ) -> collections.abc.Awaitable[testproto.grpc.dummy_pb2.DummyReply]: | ||
| """UnaryUnary""" | ||
|
|
||
| @abc.abstractmethod | ||
| def UnaryStream( | ||
| self, | ||
| request: testproto.grpc.dummy_pb2.DummyRequest, | ||
| context: grpc.aio.ServicerContext[testproto.grpc.dummy_pb2.DummyRequest, collections.abc.AsyncIterator[testproto.grpc.dummy_pb2.DummyReply]], | ||
| ) -> collections.abc.AsyncIterator[testproto.grpc.dummy_pb2.DummyReply]: | ||
| """UnaryStream""" | ||
|
|
||
| @abc.abstractmethod | ||
| def StreamUnary( | ||
| self, | ||
| request_iterator: collections.abc.AsyncIterator[testproto.grpc.dummy_pb2.DummyRequest], | ||
| context: grpc.aio.ServicerContext[collections.abc.AsyncIterator[testproto.grpc.dummy_pb2.DummyRequest], collections.abc.Awaitable[testproto.grpc.dummy_pb2.DummyReply]], | ||
| ) -> collections.abc.Awaitable[testproto.grpc.dummy_pb2.DummyReply]: | ||
| """StreamUnary""" | ||
|
|
||
| @abc.abstractmethod | ||
| def StreamStream( | ||
| self, | ||
| request_iterator: collections.abc.AsyncIterator[testproto.grpc.dummy_pb2.DummyRequest], | ||
| context: grpc.aio.ServicerContext[collections.abc.AsyncIterator[testproto.grpc.dummy_pb2.DummyRequest], collections.abc.AsyncIterator[testproto.grpc.dummy_pb2.DummyReply]], | ||
| ) -> collections.abc.AsyncIterator[testproto.grpc.dummy_pb2.DummyReply]: | ||
| """StreamStream""" | ||
|
|
||
| def add_DummyServiceServicer_to_server(servicer: DummyServiceServicer, server: grpc.aio.Server) -> None: ... | ||
|
|
||
| _DeprecatedServiceDeprecatedMethodType: typing_extensions.TypeAlias = grpc.aio.UnaryUnaryMultiCallable[ | ||
| testproto.grpc.dummy_pb2.DeprecatedRequest, | ||
| testproto.grpc.dummy_pb2.DummyReply, | ||
| ] | ||
| _DeprecatedServiceDeprecatedMethodNotDeprecatedRequestType: typing_extensions.TypeAlias = grpc.aio.UnaryUnaryMultiCallable[ | ||
| testproto.grpc.dummy_pb2.DummyRequest, | ||
| testproto.grpc.dummy_pb2.DummyReply, | ||
| ] | ||
| @deprecated("""This service is deprecated""") | ||
| class DeprecatedServiceStub: | ||
| """Marking the service as deprecated""" | ||
|
|
||
| def __init__(self, channel: grpc.aio.Channel) -> None: ... | ||
|
|
||
| DeprecatedMethod: _DeprecatedServiceDeprecatedMethodType | ||
| """DeprecatedMethod""" | ||
|
|
||
| DeprecatedMethodNotDeprecatedRequest: _DeprecatedServiceDeprecatedMethodNotDeprecatedRequestType | ||
| """DeprecatedMethodNotDeprecatedRequest""" | ||
|
|
||
| @deprecated("""This service is deprecated""") | ||
| class DeprecatedServiceServicer(metaclass=abc.ABCMeta): | ||
| """Marking the service as deprecated""" | ||
|
|
||
| @abc.abstractmethod | ||
| def DeprecatedMethod( | ||
| self, | ||
| request: testproto.grpc.dummy_pb2.DeprecatedRequest, | ||
| context: grpc.aio.ServicerContext[testproto.grpc.dummy_pb2.DeprecatedRequest, collections.abc.Awaitable[testproto.grpc.dummy_pb2.DummyReply]], | ||
| ) -> collections.abc.Awaitable[testproto.grpc.dummy_pb2.DummyReply]: | ||
| """DeprecatedMethod""" | ||
|
|
||
| @abc.abstractmethod | ||
| def DeprecatedMethodNotDeprecatedRequest( | ||
| self, | ||
| request: testproto.grpc.dummy_pb2.DummyRequest, | ||
| context: grpc.aio.ServicerContext[testproto.grpc.dummy_pb2.DummyRequest, collections.abc.Awaitable[testproto.grpc.dummy_pb2.DummyReply]], | ||
| ) -> collections.abc.Awaitable[testproto.grpc.dummy_pb2.DummyReply]: | ||
| """DeprecatedMethodNotDeprecatedRequest""" | ||
|
|
||
| @deprecated("""This service is deprecated""") | ||
| def add_DeprecatedServiceServicer_to_server(servicer: DeprecatedServiceServicer, server: grpc.aio.Server) -> None: ... | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """ | ||
| @generated by mypy-protobuf. Do not edit manually! | ||
| isort:skip_file | ||
| """ | ||
|
|
||
| import abc | ||
| import collections.abc | ||
| import google.protobuf.empty_pb2 | ||
| import grpc.aio | ||
| import sys | ||
| import testproto.test_pb2 | ||
|
Check failure on line 11 in test/generated_async_only/testproto/grpc/import_pb2_grpc.pyi
|
||
| import typing | ||
|
|
||
| if sys.version_info >= (3, 10): | ||
| import typing as typing_extensions | ||
| else: | ||
| import typing_extensions | ||
|
|
||
|
|
||
| GRPC_GENERATED_VERSION: str | ||
| GRPC_VERSION: str | ||
| _SimpleServiceUnaryUnaryType: typing_extensions.TypeAlias = grpc.aio.UnaryUnaryMultiCallable[ | ||
| google.protobuf.empty_pb2.Empty, | ||
| testproto.test_pb2.Simple1, | ||
| ] | ||
| _SimpleServiceUnaryStreamType: typing_extensions.TypeAlias = grpc.aio.UnaryUnaryMultiCallable[ | ||
| testproto.test_pb2.Simple1, | ||
| google.protobuf.empty_pb2.Empty, | ||
| ] | ||
| _SimpleServiceNoCommentType: typing_extensions.TypeAlias = grpc.aio.UnaryUnaryMultiCallable[ | ||
| testproto.test_pb2.Simple1, | ||
| google.protobuf.empty_pb2.Empty, | ||
| ] | ||
| class SimpleServiceStub: | ||
| """SimpleService""" | ||
|
|
||
| def __init__(self, channel: grpc.aio.Channel) -> None: ... | ||
|
|
||
| UnaryUnary: _SimpleServiceUnaryUnaryType | ||
| """UnaryUnary""" | ||
|
|
||
| UnaryStream: _SimpleServiceUnaryStreamType | ||
| """UnaryStream""" | ||
|
|
||
| NoComment: _SimpleServiceNoCommentType | ||
|
|
||
| class SimpleServiceServicer(metaclass=abc.ABCMeta): | ||
| """SimpleService""" | ||
|
|
||
| @abc.abstractmethod | ||
| def UnaryUnary( | ||
| self, | ||
| request: google.protobuf.empty_pb2.Empty, | ||
| context: grpc.aio.ServicerContext[google.protobuf.empty_pb2.Empty, collections.abc.Awaitable[testproto.test_pb2.Simple1]], | ||
| ) -> collections.abc.Awaitable[testproto.test_pb2.Simple1]: | ||
| """UnaryUnary""" | ||
|
|
||
| @abc.abstractmethod | ||
| def UnaryStream( | ||
| self, | ||
| request: testproto.test_pb2.Simple1, | ||
| context: grpc.aio.ServicerContext[testproto.test_pb2.Simple1, collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]], | ||
| ) -> collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]: | ||
| """UnaryStream""" | ||
|
|
||
| @abc.abstractmethod | ||
| def NoComment( | ||
| self, | ||
| request: testproto.test_pb2.Simple1, | ||
| context: grpc.aio.ServicerContext[testproto.test_pb2.Simple1, collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]], | ||
| ) -> collections.abc.Awaitable[google.protobuf.empty_pb2.Empty]: ... | ||
|
|
||
| def add_SimpleServiceServicer_to_server(servicer: SimpleServiceServicer, server: grpc.aio.Server) -> None: ... | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing typed constructor, in sync as well