danielgtaylor / danielgtaylor/python-betterproto

default value in oneof content

Aperta
#167 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
1.8k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Riproduci il problema usando lo schema oneof mostrato e le chiamate a to_dict(betterproto.Casing.SNAKE, ...) di betterproto. Confronta l'output con il comportamento ufficiale di MessageToJson, concentrandoti sul fatto che i membri oneof non impostati vengano emessi. Il lavoro è completo quando la serializzazione include solo il membro fixed_gate selezionato, mantenendo i campi previsti che non sono oneof.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend-api-design
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.