danielgtaylor / danielgtaylor/python-betterproto

Add support for extending the class generated for a given Message

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

説明

Currently, the library provides some automated conversion between the Well-known Google types (eg Timestamp <=> datetime).

Projects may wish to use similar conversion rules between some protobuf messages and internal types in their code (for instance, `UUID` or `Decimal`).
Would it be possible to add some configuration options to the plugin so that the user may configure their own field converters, or at least inject methods and properties to the auto-generated dataclasses?

Ideally, I'd like to be able to get:
```python
@dataclass
class Transaction(betterproto.Message):
id: foo.UUID
amount: foo.Decimal
```

Another option would be to have:
```python
@dataclass
class Decimal(betterproto.Message):
coefficient: int
exponent: int

@property
def decimal(self):
return foo.convert_from_message(self)

@decimal.setter
def decimal(self, value):
return foo.convert_to_message(self, value)
```

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

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

調査の方向性

Issueにはファイルやテストの記載がないため、まずpluginのエントリーポイントとprotobuf Message dataclassesを生成するコードを見つけます。要求されている設定可能なフィールドコンバーターと、メソッドおよびプロパティの注入を比較し、どのアプローチを選択したかを文書化します。ユーザーがUUIDやDecimalなどの型の変換を定義し、生成されたフィールドに示されているようにアクセスできれば完了です。

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

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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