eiffel-community / eiffel-community/eiffel-pythonlib

Use pydantic instead of dicts

Aperta
#24 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
8
Fork
12
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Description
Instead of just storing the event contents as three anonymous dicts we should use [pydantic](https://pypi.org/project/pydantic/) to allow proper typed instance attributes. I tried it out with the ArtC event in https://github.com/magnusbaeck/eiffel-pythonlib/commit/59136e4188914ec8530ba658cef1b2e64f1ba185. Writing these classes by hand is rather boring so we should explore using [github.com/koxudaxi/datamodel-code-generator](https://github.com/koxudaxi/datamodel-code-generator) to generate the code.

### Motivation
Typed classes would enable linters and IDEs to help out when writing code that accesses events.

### Exemplification
I'd expect any piece of code that creates events would be easier to write. Reasonable people may disagree, but pydantic-based classes can be initialized from a dict so you could continue working with dicts if you prefer (but the syntax would be slightly different so it would break backwards compatibility).

### Benefits
See Motivation, above.

### Possible Drawbacks
It's not clear how we should deal with different versions of the events. When producing events we can probably just use the latest known version, but what do we do when deserializing events of old versions? They might not be acceptable to the current version of the schema (which is what the pydantic model would contain). Should we version the event classes too, when necessary?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia esaminando i dict dei contenuti degli eventi esistenti e l’implementazione dell’evento ArtC nel commit 59136e4, quindi esamina come vengono creati e deserializzati gli eventi. Definisci come devono funzionare i modelli Pydantic generati e la compatibilità tra le versioni degli eventi prima di tentare la modifica; il lavoro è completato quando il design risolve la deserializzazione delle versioni precedenti e mantiene o modifica deliberatamente l’utilizzo basato su dict.

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

Valutazione

Stack tecnologico
python
Ambito
backend-api-design, distributed-systems
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.