Closed
Description
In Flask, we have the following lines:
try:
import dotenv
except ImportError:
dotenv = None
Running mypy shows an error:
src/flask/cli.py:25: error: Incompatible types in assignment (expression has type "None", variable has type Module)
However, adding a # type: ignore
comment, then running mypy through tox shows an error about the ignore:
src/flask/cli.py:25: error: unused 'type: ignore' comment
Running tox without the comment shows everything passing.
So we're left in the situation where we need to pass in CI, but if anyone runs mypy locally they see this error, fix it, then CI fails for them.
What's extra strange is that right below the failing code is another optional import, with the ignore comment, that passes both locally and through tox.
try:
import ssl
except ImportError:
ssl = None # type: ignore
- Mypy version used: 0.812
- Mypy configuration options from
setup.cfg
: https://github.com/pallets/flask/blob/b5518e23f5b85ba6e069a8151ed42209947f3849/setup.cfg#L89-L105 - Python version used: 3.9.1