danielgtaylor / danielgtaylor/python-betterproto
OneOf Enforcement?
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 234
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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?
コントリビューションガイド
調査の方向性
レポートに示されているデモ protobuf と生成された OneThing のエントリポイント、つまり構築、bytes(o)、OneThing.FromString から始めます。複数バリアントの動作を再現し、コンストラクターとシリアライゼーションのラウンドトリップを比較します。プロジェクトにおける正規の強制箇所と、期待される oneof の動作が明確に決定され、文書化または実装されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api, backend-api-design
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100