danielgtaylor / danielgtaylor/python-betterproto

Add support for extending the class generated for a given Message

Offen
#253 0 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
234
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.