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

Introduce Pydantic #177

Open
alecandido opened this issue Dec 9, 2022 · 0 comments
Open

Introduce Pydantic #177

alecandido opened this issue Dec 9, 2022 · 0 comments
Labels
enhancement New feature or request output Output format and management refactor Refactor code

Comments

@alecandido
Copy link
Member

alecandido commented Dec 9, 2022

I introduced dataclasses to replace Python dict in order to leverage more the static analyzer.

Now that they are in place (or even better, after #172) we could take one step more and make them pydantic.dataclasses.
They are designed as a drop-in replacement of standard library ones, and they perform a type check also at runtime, giving more helpful errors in case of issues.

Possible cons all stem from the consideration that "it is a further dependency, better one less than one more", but this consideration underlying motivations are mainly:

  • reliability, but pydantic is reliable, since it is used by big Python packages, and backed by known sponsors; so it might be not as reliable as NumPy, but reliable enough
  • extra complexity, but being a drop-in replacement, it should not require extra effort than usual dataclass, we just need to change imports

Another concern might be the performance deterioration, but we never use dataclasses in performance critical code (or Python constructs in general), so this really does not apply.
On the other hand, the code where dataclasses are used is really a complex part, so the benefit of improving runtime errors is possibly huge.

Runtime errors are not needed if we have static analysis always in place, but I am rather convinced that there are several occasions in which static analysis is not really performed (including during development).
In this respect, more about this in #178.

@felixhekhorn felixhekhorn added enhancement New feature or request refactor Refactor code output Output format and management labels Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request output Output format and management refactor Refactor code
Projects
None yet
Development

No branches or pull requests

2 participants