pytoolz / toolz

A functional standard library for Python.
http://toolz.readthedocs.org/
Other
4.57k stars 258 forks source link

Add type hints #576

Open getzze opened 3 months ago

getzze commented 3 months ago

This is a huge PR, but hopefully it is not too hard to review.

To type check the code I had to setup mypy and I found it was simpler to also add a pyproject.toml file and bump the minimal python version to 3.8 (3.7 is not supported anymore anyway). I also set up a ruff workflow in the pyproject.toml file, I find it very useful to lint and format the code.

All tests are passing, mypy and ruff give no errors.

The problem to review this PR is that I modified the python code sometimes, to improve type checking. Maybe I can add comments where the code was modified to make it easier to review. Some examples of things that I modified:

Also, I added a dependency to typing_extensions, that is a backport of typing improvements to older python versions. It can be removed, losing a bit of type checking for functoolz.excepts and functoolz.juxt.

Related PR: #516 #502 Issue: #496

eriknw commented 3 months ago

wow, nice! Thanks @getzze! I'm in the process of moving so it may take me some time to properly review this, but know that this is appreciated and likely to go in :)