The same proto defination, if we put the message in another file and imported it, then the betterproto will generate wrong stubs.
See: No arguments are generated for stub methods when using import with proto defination #23
Clone this repo, and run bash -x run.sh
syntax = "proto3";
package puppet_grpc;
message DingRequest {
string data = 1;
}
message DingResponse {}
service Puppet {
rpc Ding (DingRequest) returns (DingResponse) {}
}The proto files are in proto_without_import/ directory.
It generates right: ding(self, *, data: str = "")
@dataclass
class DingRequest(betterproto.Message):
data: str = betterproto.string_field(1)
@dataclass
class DingResponse(betterproto.Message):
pass
class PuppetStub(betterproto.ServiceStub):
async def ding(self, *, data: str = "") -> DingResponse:
request = DingRequest()
request.data = data
return await self._unary_unary(
"/puppet_grpc.Puppet/Ding", request, DingResponse,
)The proto files are in proto_with_import/ directory.
It generates WRONG: ding(self)
async def ding(self) -> puppet_message.DingResponse:
request = puppet_message.DingRequest()
return await self._unary_unary(
"/puppet_grpc.Puppet/Ding", request, puppet_message.DingResponse,
)run ./run.sh will get the following unexpected python result:
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: puppet_service.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
import grpclib
from . import puppet_message
class PuppetStub(betterproto.ServiceStub):
async def ding(self) -> puppet_message.DingResponse:
request = puppet_message.DingRequest()
return await self._unary_unary(
"/puppet_grpc.Puppet/Ding", request, puppet_message.DingResponse,
)- Code & Docs © 2018-now Huan LI <zixia@zixia.net>
- Code released under the Apache-2.0 License
- Docs released under Creative Commons
