danielgtaylor / danielgtaylor/python-betterproto
Add support for extending the class generated for a given Message
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 234
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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)
```
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.