danielgtaylor / danielgtaylor/python-betterproto

Add ParseFromString for compatibility

オープン
#323 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
good first issue
主要言語
Python
スター
1.8k
フォーク
234
PR マージ指標
30日以内にマージされた PR はありません

説明

I currently use the standard protobuf method `ParseFromString` quite a bit, but noticed that the generated `betterproto` dataclasses don't have this method, but they do have `SerializeToString` for compatibility.

Is there a reason `ParseFromString` isn't added?

I currently have a reasonable amount of repositories that use `ParseFromString`, which would require me to refactor quite a bit extra at once without this method.

For clarity, here's an example of what some of the code looks like right now:
```protobuf
syntax = "proto3";

package hello;

message Hello {
string message = 1;
}
```

```python
from hello_pb2 import Hello

hello = Hello()
hello.ParseFromString(bytes(Hello)) # dummy example
```

but it would be nice if I could do the following with betterproto:
```python
from dataclasses import dataclass
import betterproto

@dataclass
class Hello(betterproto.Message):
"""Greeting represents a message you can tell a user."""

message: str = betterproto.string_field(1)

hello = Hello(message='betterproto')
hello.ParseFromString(bytes(Hello)) # dummy example
```

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず betterproto Message API と既存の SerializeToString 実装を読み、互換性メソッドを配置すべき場所を確認してください。Issue の Hello の例を使って parsing をどのように公開すべきかを確認し、結果の dataclass が標準的な protobuf の動作と一致することを検証してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。