danielgtaylor / python-betterproto

Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
MIT License
1.54k stars 216 forks source link

Empty fields which one of None #548

Closed dura0ok closed 10 months ago

dura0ok commented 10 months ago

Summary

simple structs not parsing

Reproduction Steps

@dataclass class GameMessage(betterproto.Message): """Общий формат любого UDP-сообщения"""

msg_seq: int = betterproto.int64_field(1)
sender_id: int = betterproto.int32_field(10)
receiver_id: int = betterproto.int32_field(11)
ping: "GameMessagePingMsg" = betterproto.message_field(2, group="Type")
steer: "GameMessageSteerMsg" = betterproto.message_field(3, group="Type")
ack: "GameMessageAckMsg" = betterproto.message_field(4, group="Type")
state: "GameMessageStateMsg" = betterproto.message_field(5, group="Type")
announcement: "GameMessageAnnouncementMsg" = betterproto.message_field(
    6, group="Type"
)
join: "GameMessageJoinMsg" = betterproto.message_field(7, group="Type")
error: "GameMessageErrorMsg" = betterproto.message_field(8, group="Type")
role_change: "GameMessageRoleChangeMsg" = betterproto.message_field(9, group="Type")
discover: "GameMessageDiscoverMsg" = betterproto.message_field(12, group="Type")

@dataclass class GameMessageAckMsg(betterproto.Message): pass

msg = GameMessage(ack=GameMessageAckMsg(), sender_id=3) serialized = bytes(msg) deserialized = GameMessage().parse(serialized) print(betterproto.which_one_of(deserialized, "Type"))

Expected Results

(''ack", None)

Actual Results

('', None)

System Information

libprotoc 3.12.4 Python 3.10.12 Name: betterproto Version: 1.2.5 Summary: A better Protobuf / gRPC generator & library Home-page: http://github.com/danielgtaylor/python-betterproto Author: Daniel G. Taylor Author-email: danielgtaylor@gmail.com License: MIT Location: /home/durachok/PycharmProjects/asdasddasd/.venv/lib/python3.10/site-packages Requires: grpclib, stringcase Required-by:

Checklist

Gobot1234 commented 10 months ago

This I don't think is an issue on v2, please install it

dura0ok commented 10 months ago

It helped, thanks When can we expect a stable 2.0 version? @Gobot1234

Gobot1234 commented 10 months ago

No eta sorry