Skip to content

Conversation

HU90m
Copy link
Contributor

@HU90m HU90m commented Feb 25, 2025

I've found writing more data oriented python has made my projects less bug prone and easily maintainable. Pydantic is a very popular library that can provide runtime data validation from standard type hints.

This PR shows how Pydantic could be introduced incrementally. I've used the @validate_call decorator to check the arguments provided to unique_dirs. I've also made Library a data class with runtime type checking on initialization and assignment. (I normally like to use frozen=True, but was trying to keep changes to a minimum.)

I have also bumped the python version to 3.10. I chose 3.10 because it adds nice ergonomic improvements to type hints, e.g. str | list as oppose to Union[str, list]. Version 3.9 will also become end-of-life before the end of the year. The latest Pydantic only requires python version 3.8, though so we don't have to jump to 3.10 in order to use it.

Python 3.10 has a nice syntax features for type annotations, such as `|`
unions, and 3.9 will be end of life by the end of 2025.

Pydantic has been added to allow runtime type checking.
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

Successfully merging this pull request may close these issues.

1 participant