Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pydantic instead of dicts #24

Open
magnusbaeck opened this issue Dec 8, 2020 · 0 comments
Open

Use pydantic instead of dicts #24

magnusbaeck opened this issue Dec 8, 2020 · 0 comments

Comments

@magnusbaeck
Copy link
Member

Description

Instead of just storing the event contents as three anonymous dicts we should use pydantic to allow proper typed instance attributes. I tried it out with the ArtC event in magnusbaeck@59136e4. Writing these classes by hand is rather boring so we should explore using 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant