Closed nyurik closed 4 years ago
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: https://github.com/danielgtaylor/python-betterproto/blob/3546f55146a4b41d6cfebb7872da0c17bd9277a1/betterproto/__init__.py#L594
oneof
TileValue
t
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")
Added testcase namespace_builtin_types
namespace_builtin_types
This should have been fixed now for all types mentioned.
Thank you for your report!
This
oneof
definition generates valid Python code, but later it is not possible to parse or create an instance ofTileValue
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 sayingt
is not a class: https://github.com/danielgtaylor/python-betterproto/blob/3546f55146a4b41d6cfebb7872da0c17bd9277a1/betterproto/__init__.py#L594