python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

Protoc proto file , AccountInfo -> CcountInfo, why and how to solve

Open weixiaovision opened this issue 2 years ago • 7 comments

message LoginInfo { optional string login_channel = 1; optional string open_id = 2; // optional DeviceInfo deviceInfo = 3; optional AccountInfo accountInfo = 4; optional int64 robotIntoId = 5; }

@dataclass class LoginInfo(betterproto.Message): login_channel: str = betterproto.string_field(1) open_id: str = betterproto.string_field(2) device_info: "DeviceInfo" = betterproto.message_field(3) account_info: "CcountInfo" = betterproto.message_field(4) robot_into_id: int = betterproto.int64_field(5)

weixiaovision avatar Sep 23 '22 06:09 weixiaovision

What version of betterproto are you using that does this? I can't reproduce this bug

cat test.proto
message AccountInfo {}
message DeviceInfo {}
message LoginInfo {
optional string login_channel = 1;
optional string open_id = 2; //
optional DeviceInfo deviceInfo = 3;
optional AccountInfo accountInfo = 4;
optional int64 robotIntoId = 5;
}

protoc -I . --python_betterproto_out=lib test.proto
[libprotobuf WARNING google/protobuf/compiler/parser.cc:646] No syntax specified for the proto file: test.proto. Please use 'syntax = "proto2";' or 'syntax = "proto3";' to specify a syntax version. (Defaulted to proto2 syntax.)

Writing __init__.py

cat lib/__init__.py
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: test.proto
# plugin: python-betterproto
from dataclasses import dataclass

import betterproto


@dataclass(eq=False, repr=False)
class AccountInfo(betterproto.Message):
    pass


@dataclass(eq=False, repr=False)
class DeviceInfo(betterproto.Message):
    pass


@dataclass(eq=False, repr=False)
class LoginInfo(betterproto.Message):
    login_channel: str = betterproto.string_field(1)
    open_id: str = betterproto.string_field(2)
    device_info: "DeviceInfo" = betterproto.message_field(3)
    account_info: "AccountInfo" = betterproto.message_field(4)
    robot_into_id: int = betterproto.int64_field(5)

Gobot1234 avatar Sep 26 '22 17:09 Gobot1234

1.2.5

weixiaovision avatar Sep 27 '22 04:09 weixiaovision

many proto files exist this problem

weixiaovision avatar Sep 27 '22 04:09 weixiaovision

I probably know the problem. I use proto2. Is there any way to solve it

weixiaovision avatar Sep 27 '22 07:09 weixiaovision

After I changed to proto3, the problem still exists

weixiaovision avatar Sep 27 '22 07:09 weixiaovision

When I change betterproto 2.0.0b5, I will report the following mistakes When I change it, I will report the following mistakes image

weixiaovision avatar Sep 27 '22 07:09 weixiaovision

Can you try using the commands suggested in the README? it seemed very parsable to my protoc

Gobot1234 avatar Sep 27 '22 10:09 Gobot1234