AFM-SPM / TopoStats

An AFM image analysis program to batch process data and obtain statistics from images
https://afm-spm.github.io/TopoStats/
GNU Lesser General Public License v3.0
60 stars 11 forks source link

Apply typehints consistently across the code base #516

Open ns-rse opened 1 year ago

ns-rse commented 1 year ago

Typehints (see PEP484) make it easier to read and understand code (by default the "type" of objects in Python is dynamically determined and can change, adding typehints clarifies intent). Newer code that has been developed includes typehints.

The MonkeyType tool can be used to determine and apply types across an existing code base and the pytest-monkeytype package facilitates applying this to existing code bases.

Once in place we can then introduce type checkers such as mypy into the pre-commit pipeline.

MaxGamill-Sheffield commented 1 week ago

Is this still and issue or a continuous? We're just tidying up the issue list :)

As numpydoc-validation is part of the pre-commit hooks, and thus needs typehints for functions and classes, can this be considered closed?

ns-rse commented 1 week ago

I don't think this can be closed yet until we have enabled a mypy pre-commit hook so that we are consistently checking that type hints are always correct.

mypy pre-commit

If I run mypy topostats against main I get the following that needs fixing...

❱ mypy topostats
...
Found 544 errors in 30 files (checked 35 source files)

On the tests/ directory there are...

❱ mypy tests --exclude tests/measure/conftest.py --exclude tests/tracing/conftest.py
...
Found 824 errors in 51 files (checked 32 source files)

So we're a long way off achieving correct typehints that pass mypy.

Whilst incredibly useful in the long run its not a particularly fun task to undertake and other tasks (features) take priority.