techservicesillinois / secdev-quarantinenetwork

Source code for the Quarantine Network API and self-service portal
Other
2 stars 0 forks source link

Add mypy typing #5

Closed ddriddle closed 4 years ago

ddriddle commented 4 years ago

@edthedev @mpitcel @zcarrington since this project is still in its infancy I think it would be wise to add static typing. Typing in Python 3 is optional and not enforced at runtime but does allow for static analysis using mypy that can catch bugs that would be hard to find otherwise. I wrote some Python 3 code that uses static typing here:

https://github.com/techservicesillinois/terraform-aws-cloudfront-lambda-basic-auth/blob/master/src/lambda/auth.py

The following link is a useful cheat sheet:

https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html

To actually enforce the typing you would add mypy to your Makefile something like this:

drone: 
    flake8 $(BIN) lambda tests
    mypy lambda tests
    coverage run -m unittest
    coverage report -m --fail-under=100 || (coverage html; exit 1)
edthedev commented 4 years ago

I like it. This is new and should remain a relatively small amount of code - and it's web facing - which is a good place to get the extra benefits of that kind of check. Let's go for it.

zdc217 commented 4 years ago

This is a fantastic idea.

edthedev commented 4 years ago

@ddriddle Can you start us off with a PR that adds a GitHub actions hook that runs the test?

ddriddle commented 4 years ago

@edthedev can do.