Add mypy with some initial types
The main useful thing here are the TypedDict types in templates.py,
which define the structure of the templates, with required and optional
members. For the rest, we just sprinkle some type ignore comments for
now, to make mypy pass everywhere. (Some of the Flask or Werkzeug
ignores are due to bugs that are already fixed on master, but not yet in
a published release.)