danielgtaylor / danielgtaylor/python-betterproto
OneOf Enforcement?
- Langage dominant
- Python
- Étoiles
- 1.8k
- Forks
- 234
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
Thanks for all of your work on betterproto, it's been immensely helpful.
What is betterproto's canonical way of enforcing Protobuf `oneof`s are only set to one variant?
From this demo-protobuf:
```proto
syntax = "proto3";
package demo;
message Thing1 {
string name = 1;
}
message Thing2 {
string name = 1;
}
message Thing3 {
string name = 1;
}
message Thing4 {
string name = 1;
}
message OneThing {
oneof t {
Thing1 t1 = 1;
Thing2 t2 = 2;
Thing3 t3 = 3;
Thing4 t4 = 4;
}
}
```
Creating a `OneThing` appears produce default values of non-used `oneof` variants.
```
In [2]: OneThing(t1=Thing1(name='cy'))
Out[2]: OneThing(t1=Thing1(name='cy'), t2=Thing2(name=''), t3=Thing3(name=''), t4=Thing4(name=''))
```
Moreover it'll initialize more than one of them:
```
In [5]: o = OneThing(t1=Thing1(name='cy'), t2=Thing2(name='huh'))
In [6]: o
Out[6]: OneThing(t1=Thing1(name='cy'), t2=Thing2(name='huh'), t3=Thing3(name=''), t4=Thing4(name=''))
```
And that combination passes a round-trip through serialization and de-serialization:
```
In [7]: OneThing.FromString(bytes(o))
Out[7]: OneThing(t1=Thing1(name=''), t2=Thing2(name='huh'), t3=Thing3(name=''), t4=Thing4(name=''))
```
What's the intent as to where this *should* be enforced? Outside of betterproto?
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par le protobuf de démonstration et les points d’entrée générés de OneThing présentés dans le rapport : construction, bytes(o) et OneThing.FromString. Reproduisez le comportement avec plusieurs variantes et comparez le constructeur avec l’aller-retour de sérialisation. C’est terminé lorsque l’emplacement canonique du projet pour l’application et le comportement oneof attendu sont clairement décidés et documentés ou implémentés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- api, backend-api-design
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 25/100