From 3322a3ac2f93691beafbdd1c51fd8286b5dab506 Mon Sep 17 00:00:00 2001 From: zerlok Date: Sun, 25 Aug 2024 15:03:09 +0200 Subject: [PATCH] fix python grpc stubs gen * always return call instance in grpc stub (even if stub uses grpc.aio.Channel) --- README.md | 2 +- pyproject.toml | 2 +- src/pyprotostuben/protobuf/builder/grpc.py | 1 - .../cases/000_greeting/expected_gen/greeting_pb2_grpc.pyi | 2 +- .../expected_gen/grpc_service_pb2_grpc.pyi | 8 ++++---- .../expected_gen/message_nesting_pb2_grpc.pyi | 4 ++-- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index a0c3272..1925064 100644 --- a/README.md +++ b/README.md @@ -135,5 +135,5 @@ class GreeterStub: def __init__(self, channel: grpc.aio.Channel) -> None:... - async def Greet(self, request: greeting_pb2.GreetRequest, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[greeting_pb2.GreetRequest, greeting_pb2.GreetResponse]:... + def Greet(self, request: greeting_pb2.GreetRequest, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[greeting_pb2.GreetRequest, greeting_pb2.GreetResponse]:... ``` diff --git a/pyproject.toml b/pyproject.toml index 1e80e19..75ad006 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyprotostuben" -version = "0.1.1" +version = "0.1.2" description = "" authors = ["zerlok "] readme = "README.md" diff --git a/src/pyprotostuben/protobuf/builder/grpc.py b/src/pyprotostuben/protobuf/builder/grpc.py index 74e6ac3..88b0798 100644 --- a/src/pyprotostuben/protobuf/builder/grpc.py +++ b/src/pyprotostuben/protobuf/builder/grpc.py @@ -227,7 +227,6 @@ def build_grpc_stub_method_def(self, info: MethodInfo) -> ast.stmt: ), ], returns=response, - is_async=not self.__is_sync, ) def build_grpc_stub_method_request_response_refs(self, info: MethodInfo) -> t.Tuple[ast.expr, ast.expr]: diff --git a/tests/integration/cases/000_greeting/expected_gen/greeting_pb2_grpc.pyi b/tests/integration/cases/000_greeting/expected_gen/greeting_pb2_grpc.pyi index 3247858..943dae8 100644 --- a/tests/integration/cases/000_greeting/expected_gen/greeting_pb2_grpc.pyi +++ b/tests/integration/cases/000_greeting/expected_gen/greeting_pb2_grpc.pyi @@ -16,4 +16,4 @@ class GreeterStub: def __init__(self, channel: grpc.aio.Channel) -> None:... - async def Greet(self, request: greeting_pb2.GreetRequest, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[greeting_pb2.GreetRequest, greeting_pb2.GreetResponse]:... \ No newline at end of file + def Greet(self, request: greeting_pb2.GreetRequest, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[greeting_pb2.GreetRequest, greeting_pb2.GreetResponse]:... \ No newline at end of file diff --git a/tests/integration/cases/002_grpc_service/expected_gen/grpc_service_pb2_grpc.pyi b/tests/integration/cases/002_grpc_service/expected_gen/grpc_service_pb2_grpc.pyi index c983cd8..fde750e 100644 --- a/tests/integration/cases/002_grpc_service/expected_gen/grpc_service_pb2_grpc.pyi +++ b/tests/integration/cases/002_grpc_service/expected_gen/grpc_service_pb2_grpc.pyi @@ -25,10 +25,10 @@ class ServiceStub: def __init__(self, channel: grpc.aio.Channel) -> None:... - async def DoUnaryUnary(self, request: grpc_service_pb2.Request, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[grpc_service_pb2.Request, grpc_service_pb2.Response]:... + def DoUnaryUnary(self, request: grpc_service_pb2.Request, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[grpc_service_pb2.Request, grpc_service_pb2.Response]:... - async def DoUnaryStream(self, request: grpc_service_pb2.Request, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryStreamCall[grpc_service_pb2.Request, grpc_service_pb2.Response]:... + def DoUnaryStream(self, request: grpc_service_pb2.Request, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryStreamCall[grpc_service_pb2.Request, grpc_service_pb2.Response]:... - async def DoStreamUnary(self, request: typing.AsyncIterator[grpc_service_pb2.Request], *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.StreamUnaryCall[grpc_service_pb2.Request, grpc_service_pb2.Response]:... + def DoStreamUnary(self, request: typing.AsyncIterator[grpc_service_pb2.Request], *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.StreamUnaryCall[grpc_service_pb2.Request, grpc_service_pb2.Response]:... - async def DoStreamStream(self, request: typing.AsyncIterator[grpc_service_pb2.Request], *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.StreamStreamCall[grpc_service_pb2.Request, grpc_service_pb2.Response]:... \ No newline at end of file + def DoStreamStream(self, request: typing.AsyncIterator[grpc_service_pb2.Request], *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.StreamStreamCall[grpc_service_pb2.Request, grpc_service_pb2.Response]:... \ No newline at end of file diff --git a/tests/integration/cases/003_message_nesting/expected_gen/message_nesting_pb2_grpc.pyi b/tests/integration/cases/003_message_nesting/expected_gen/message_nesting_pb2_grpc.pyi index df114e9..7a4c94c 100644 --- a/tests/integration/cases/003_message_nesting/expected_gen/message_nesting_pb2_grpc.pyi +++ b/tests/integration/cases/003_message_nesting/expected_gen/message_nesting_pb2_grpc.pyi @@ -19,6 +19,6 @@ class ComplexStub: def __init__(self, channel: grpc.aio.Channel) -> None:... - async def UnaryUnary(self, request: message_nesting_pb2.Message1, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[message_nesting_pb2.Message1, message_nesting_pb2.CombinedMessage]:... + def UnaryUnary(self, request: message_nesting_pb2.Message1, *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.UnaryUnaryCall[message_nesting_pb2.Message1, message_nesting_pb2.CombinedMessage]:... - async def StreamStream(self, request: typing.AsyncIterator[message_nesting_pb2.Message2], *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.StreamStreamCall[message_nesting_pb2.Message2, message_nesting_pb2.CombinedMessage]:... \ No newline at end of file + def StreamStream(self, request: typing.AsyncIterator[message_nesting_pb2.Message2], *, timeout: typing.Optional[builtins.float]=None, metadata: typing.Optional[grpc.aio.MetadataType]=None, credentials: typing.Optional[grpc.CallCredentials]=None, wait_for_ready: typing.Optional[builtins.bool]=None, compression: typing.Optional[grpc.Compression]=None) -> grpc.aio.StreamStreamCall[message_nesting_pb2.Message2, message_nesting_pb2.CombinedMessage]:... \ No newline at end of file