Skip to content
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

Bugfix twice-nested messages naming error #18

Closed
wants to merge 1 commit into from
Closed

Bugfix twice-nested messages naming error #18

wants to merge 1 commit into from

Conversation

cetanu
Copy link
Collaborator

@cetanu cetanu commented Feb 6, 2020

Fixes #17

However, I'm not entirely sure what other effects this change could have

@adament
Copy link
Contributor

adament commented Mar 6, 2020

I do not think this is a full fix, if I understand the problem and code correctly the same issue should occur for enums as well. I will try to come up with a test case. Furthermore while pragmatic this solution would also avoid prefixing the name if the inner name was already prefixed in the proto file. I think this would be surprising behaviour.

@adament
Copy link
Contributor

adament commented Mar 6, 2020

I was wrong, this also fixes the issue for enums, but this solution means that you do not get prefixing of the dataclass declaration in the following case. But you do get it in the type annotation:

syntax = "proto3";

message Root {
  message Parent {
    message RootParentChild {
      string a = 1;
    }
    enum EnumChild{
      A = 0;
      B = 1;
    }
    message Child {
      string foo = 1;
    }
    reserved 1;
    repeated Child child = 2;
    repeated EnumChild enum_child=3;
    repeated RootParentChild root_parent_child=4;
    bool bar = 5;
  }
  string name = 1;
  Parent parent = 4;
}
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: test.proto
# plugin: python-betterproto
from dataclasses import dataclass
from typing import List

import betterproto


class RootParentEnumChild(betterproto.Enum):
    A = 0
    B = 1


@dataclass
class Root(betterproto.Message):
    name: str = betterproto.string_field(1)
    parent: "RootParent" = betterproto.message_field(4)


@dataclass
class RootParent(betterproto.Message):
    child: List["RootParentChild"] = betterproto.message_field(2)
    enum_child: List["RootParentEnumChild"] = betterproto.enum_field(3)
    root_parent_child: List["RootParentRootParentChild"] = betterproto.message_field(4)
    bar: bool = betterproto.bool_field(5)


@dataclass
class RootParentChild(betterproto.Message):
    a: str = betterproto.string_field(1)


@dataclass
class RootParentChild(betterproto.Message):
    foo: str = betterproto.string_field(1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Naming bug for twice-nested messages
2 participants