Skip to content

Instantly share code, notes, and snippets.

@delicb
Created October 6, 2021 18:21
Show Gist options
  • Save delicb/1faf8bb8e58cde7a352c3f9dab7bf3eb to your computer and use it in GitHub Desktop.
Save delicb/1faf8bb8e58cde7a352c3f9dab7bf3eb to your computer and use it in GitHub Desktop.
flask error handling - mypy error
xxx/__init__.py: note: In function "register_error_handlers":
xxx/__init__.py:115: error: Argument 1 has incompatible type
"Callable[[Exception], Union[Union[Response, Any, Dict[str, Any], Generator[Any, None, None]], Tuple[Union[Response, Any, Dict[str, Any], Generator[Any, None, None]], Union[Headers, Dict[str, Union[str, List[str], Tuple[str, ...]]], List[Tuple[str, Union[str, List[str], Tuple[str, ...]]]]]], Tuple[Union[Response, Any, Dict[str, Any], Generator[Any, None, None]], int], Tuple[Union[Response, Any, Dict[str, Any], Generator[Any, None, None]], int, Union[Headers, Dict[str, Union[str, List[str], Tuple[str, ...]]], List[Tuple[str, Union[str, List[str], Tuple[str, ...]]]]]], Callable[[Dict[str, Any], StartResponse], Iterable[bytes]]]]";
expected "ErrorHandlerCallable[Exception]" [arg-type]
@app.errorhandler(Exception)
^
Found 1 error in 1 file (checked 8 source files)
@app.errorhandler(Exception)
def handle_any_exception(e: Exception) -> ResponseReturnValue:
"""
Base exception handler, just log exception and return 500
"""
log.exception("unexpected error")
return jsonify({
"message": str(e)
}), 500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment