danielgtaylor / danielgtaylor/python-betterproto

Add ParseFromString for compatibility

Aperta
#323 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
good first issue
Lingua principale
Python
Stelle
1.8k
Fork
234
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia leggendo la betterproto Message API e l’implementazione esistente di SerializeToString per individuare dove devono trovarsi i metodi di compatibilità. Usa l’esempio Hello nell’issue per verificare come debba essere esposto il parsing e verifica che la dataclass risultante corrisponda al comportamento standard di protobuf.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.