fepegar / torchio

Medical imaging toolkit for deep learning
https://torchio.org
Apache License 2.0
2.07k stars 240 forks source link

Add and fix type annotations for type checking with mypy #810

Open jcreinhold opened 2 years ago

jcreinhold commented 2 years ago

πŸš€ Feature

Add and fix type annotations in torchio so it passes inspection with mypy and so end users can trust that the type annotations reflects function, class instantiation, etc. arguments and outputs.

This is follow up issue to the PR #808 and issue #807.

Motivation

The current version of torchio (v0.18.72) is not properly type annotated (some functions are missing type annotations, some have overly restrictive types, some are outdated) and fails mypy inspection on many accounts.

mypy has caught a good number of errors in my code, and proper type annotations make development much easier in a modern IDE (IMO).

Pitch

Since making torchio work properly with mypy will change a good number of files (39 it looks like, although some of the errors might be fixed by fixing the type issue elsewhere), I'll do the following:

  1. Make a mypy feature branch
  2. Define the least strict base types the project requires
  3. Fix the mypy issues in one function
  4. Commit the changes
  5. Repeat 3-4 until no more mypy errors
  6. Submit a PR

I'll avoid changing any actual functionality, although there are likely to be be some bugs caught while going through the process. If I find a potential error, I'd just raise an issue instead of correcting it.

Alternatives

Alternatively, I could make a mypy-modulename feature branch and submit a PR for each module (e.g., at the level of torchio/data/image.py or torchio/data). It might get a bit tedious, but it'd avoid a giant PR; however, type annotations are very entangled, so I'm not sure how effective that workflow would be at eliminating errors from the project.

fepegar commented 11 months ago

Hey, @jcreinhold. Are you still thinking of tackling this? Seems like a heroic feat :D