davidverweij / csv2docx

Generates .docx files from .csv files using a .docx template with mailmerge fields
MIT License
5 stars 0 forks source link

Type hinting with static type analysis #29

Closed jawrainey closed 4 years ago

jawrainey commented 4 years ago

Addresses Issue #11

What Changed (and why)?

  1. Added type annotations to all methods to prevent bugs;
  2. Added mypy package to --dev and updated noxfile.py to do static analysis by default;
  3. Added mypy to pre-commit to validate code before commits, e.g. to PRs;
  4. Made very minor tweak, e.g. removed uncommented code and bumped package version from 0.0.1 to 0.1.0 as a patch without minor version did not make semantic sense;
  5. Updated documentation to note that we use static analysis for types on pre-commit.

Running mypy identified a few issues, e.g. (i) reassigning path from a str to a path in convert(...) or (ii) the complexity of having the options list using multiple types.

How to test Changes

  1. Pull down changes locally
  2. Run poetry install && poetry shell
  3. Run poetry run nox and observe that mypy runs and is a success
  4. Verify that mypy pre-commit works: (i) remove a type hint from convert(); (ii) add the file to git; and (iii) try to make a commit. This should fail 👍

Please review @davidverweij and closes #11.