Mypy on steroids
Mypy is a nifty static type checker for Python that will help you nip nasty production bugs in the bud. Especially when you're already in the habit of generously using type hints in your code. Head over to their docs to get started if you're not using Mypy already.
Mypy is kind of slow though. On a code base of 200 Python files it already takes 2 seconds to check the code. Luckily there's a quick fix! You can run Mypy in daemon mode, and it will (partially) cache previous run results and be up to 20 times faster 🚀
To speed things up, just change the Mypy command frommypy <arguments> <file(s)>
like this:
mypy --check-untyped-defs hello_world.py
To dmypy run -- <arguments> <file(s)>
like this:
dmypy run -- --check-untyped-defs hello_world.py
The first time you run the command in daemon mode, it will still be slow as it needs to generate the cached data.
Subsequent calls will be much faster though. For the 200 file code base the run time went down from 2 seconds to just 100ms.
-
Venving like a pro
Automating Python virtual environment switching and setup in the linux command shell.
-
Open GitHub when pushing a new branch
A trick to quickly create a pull request when pushing a new branch to remote by opening the repo in your browser.
-
Fighting html form bots
A tale of fighting spam bots abusing my contact form. A series of experiments led to a simple solution to stop the bots.