Adds type hints throughout Hatchet and integrate checks with mypy #153
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As several of us (particularly myself and @pearce8) have mentioned on numerous occasions, Python's duck typing system can be a pain to deal with.
To help with this, this PR adds extensive type hinting throughout Hatchet to help with understanding what is valid input/output for functions. Additionally, this PR adds support for mypy: the most widely used static type checker for Python.
mypymakes use of the type hints added in this PR to determine whether code is written correctly, similar to how a compiler works for languages like C and C++.Besides type checking, this PR corrects numerous bugs that
mypyrevealed, ranging from minor typing issues due to reusing variables too much to functions not returning when they are supposed to (this one may actually be part of the cause of thesquashissues you were having @slabasan). One important set of things thatmypypointed out is logic for Python 2. Since we are now officially supporting Python 3.5+, this logic is no longer needed, so I have removed any such logic thatmypydetected.Finally, this PR adds mypy-based static type checking to our CI. Like
flake8andblack, this will only run for Python 3.9.Edit:
I got fed up with Black giving different formatting with different versions, so I added a devcontainer to Hatchet. This lets developers who user VSCode work in a Docker-based environment with the exact right versions of tools like black, flake8, and mypy.