Fix typing errors with upgraded mypy version.