Search code examples
pythonpython-3.xflaskmypywerkzeug

Mypy fails when using Werkzeug's abort() for throwing exceptions


When using flask.abort() (which ultimately throws an exception through Werkzeug), mypy fails because it can't see it will result in an exception:

error: Missing return statement

Is there a way to hint mypy that this will end in an exception so it should regard it as that?


Solution

  • Mypy needs the typing.NoReturn return type annotation on abort() to understand the situation. For that you need to install the separate types-Werkzeug package:

    pip install types-Werkzeug