danielgtaylor / danielgtaylor/python-betterproto

Add ParseFromString for compatibility

Offen
#323 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
good first issue
Vorherrschende Sprache
Python
Sterne
1.8k
Forks
234
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start by reading the betterproto Message API and the existing SerializeToString implementation to find where compatibility methods belong. Use the Hello example in the issue to check how parsing should be exposed and verify that the resulting dataclass matches the standard protobuf behavior.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
api
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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