danielgtaylor / danielgtaylor/python-betterproto

default value in oneof content

未關閉
#167 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
1.8k
分支
234
PR 合併指標
30 天內沒有已合併 PR

描述

oneof op {
FixedGate fixedGate = 1;
RotationGate rotationGate = 2;
CustomizedGate customizedGate = 3;
CompositeGate compositeGate = 4;
string procedureName = 5;
Measure measure = 6;
bool barrier = 7;
}

enum FixedGate {
// 1 bit
ID = 0;
X = 1;
Y = 2;
Z = 3;
H = 4;
S = 5;
SDG = 6;
T = 7;
TDG = 8;
// 2 bit
CX = 9;
CY = 10;
CZ = 11;
CH = 12;
SWAP = 13;
// 3 bit
CCX = 14;
CSWAP = 15;
}

enum RotationGate {
// 1 bit
U = 0; // Universal rotation
RX = 1;
RY = 2;
RZ = 3;
// 2 bit
CU = 4;
CRX = 5;
CRY = 6;
CRZ = 7;
}

message CustomizedGate {
Matrix matrix = 1;
}

I only set fixed_gate = 'ID'

betterproto:
json.dumps(msg.to_dict(betterproto.Casing.SNAKE, False))
{# nothing
"q_reg_list": [
1
]
},
json.dumps(msg.to_dict(betterproto.Casing.SNAKE, True))
{
"fixed_gate": "ID", # oneof default value
"rotation_gate": "U", # oneof default value
"customized_gate": {, # oneof default value
"matrix": {
"shape": [],
"array": []
}
},
"composite_gate": "RZZ", # oneof default value
"procedure_name": "", # oneof default value
"measure": { # oneof default value
"type": "X",
"c_reg_list": []
},
"barrier": false, # oneof default value
"q_reg_list": [
1
],
"argument_value_list": [],
"argument_id_list": []
},

official
MessageToJson(pbObj, preserving_proto_field_name=False)
{
"fixedGate": "ID", # oneof default value
"qRegList": [
1
],
"argumentValueList": [],
"argumentIdList": []
},
MessageToJson(pbObj, preserving_proto_field_name=True)
{
"fixedGate": "ID", # oneof default value
"qRegList": [
1
]
},

The official is right

貢獻指南

開啟貢獻指南

研究方向

使用所示的 oneof schema 和 betterproto 的 to_dict(betterproto.Casing.SNAKE, ...) 呼叫重現此問題。將輸出與官方的 MessageToJson 行為進行比較,重點關注是否會輸出未設定的 oneof 成員。完成的標準是序列化結果僅包含選取的 fixed_gate 成員,同時保留預期的非 oneof 欄位。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend-api-design
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。