Skip to content

To reproduce some issues for the python-betterproto

huan/python-betterproto-issue

Repository files navigation

python-betterproto-issue

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

Reproduce

Clone this repo, and run bash -x run.sh

The Proto

syntax = "proto3";

package puppet_grpc;

message DingRequest {
  string data = 1;
}
message DingResponse {}

service Puppet {
  rpc Ding (DingRequest) returns (DingResponse) {}
}

Without Import

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,
        )

With Import

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,
        )

Author

Huan LI (李卓桓) zixia@zixia.net

Profile of Huan LI (李卓桓) on StackOverflow

Copyright & License

  • Code & Docs © 2018-now Huan LI <zixia@zixia.net>
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons

About

To reproduce some issues for the python-betterproto

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages