Skip to content

Crash when field has the same name as a system type #53

Closed
@nyurik

Description

@nyurik

This oneof definition generates valid Python code, but later it is not possible to parse or create an instance of TileValue because the name of the field is the same as the type. Should betterproto rename such fields automatically, or at least throw an error during the code generation? I spent considerable time trying to understand why this line was saying t is not a class:

elif issubclass(t, Enum):

message Tile {
        message Value {
                oneof val {
                        string string = 1;
                        float float = 2;
                        double double = 3;
                        int64 int = 4;
                        uint64 uint = 5;
                        sint64 sint = 6;
                        bool bool = 7;
                }
        }

        repeated Value values = 1;
}
@dataclass
class Tile(betterproto.Message):
    values: List["TileValue"] = betterproto.message_field(1)


@dataclass
class TileValue(betterproto.Message):
    string: str = betterproto.string_field(1, group="val")
    float: float = betterproto.float_field(2, group="val")
    double: float = betterproto.double_field(3, group="val")
    int: int = betterproto.int64_field(4, group="val")
    uint: int = betterproto.uint64_field(5, group="val")
    sint: int = betterproto.sint64_field(6, group="val")
    bool: bool = betterproto.bool_field(7, group="val")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas testHas a (xfail) test that verifies the bugfix or featuremedium prioritysmallLow effort issue that can easily be picked up

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions