danielgtaylor / danielgtaylor/python-betterproto

Add support for extending the class generated for a given Message

Open
#253 0 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
1.8k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

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)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.