From 6909dcb2f21867af73a83707fb9a4a398ab42e2c Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Fri, 31 May 2024 17:56:15 +0200 Subject: [PATCH] Add proper type overload to determine handle_exception return type --- lib/galaxy/web/framework/middleware/error.py | 50 +++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/web/framework/middleware/error.py b/lib/galaxy/web/framework/middleware/error.py index 0bfaf764b4c0..369f05991485 100644 --- a/lib/galaxy/web/framework/middleware/error.py +++ b/lib/galaxy/web/framework/middleware/error.py @@ -16,6 +16,7 @@ from typing import ( cast, Optional, + overload, ) import markupsafe @@ -28,6 +29,7 @@ formatter, reporter, ) +from typing_extensions import Literal log = logging.getLogger(__name__) @@ -191,7 +193,7 @@ def make_catching_iter(self, app_iter, environ, sr_checker): return app_iter return CatchingIter(app_iter, environ, sr_checker, self) - def exception_handler(self, exc_info, environ) -> Optional[str]: + def exception_handler(self, exc_info, environ) -> str: simple_html_error = False if self.xmlhttp_key: get_vars = wsgilib.parse_querystring(environ) @@ -348,10 +350,54 @@ def extraData(self): } +@overload def handle_exception( exc_info, error_stream, - html=True, + html: Literal[False] = ..., + debug_mode=..., + error_email=..., + error_log=..., + show_exceptions_in_wsgi_errors=..., + error_email_from=..., + smtp_server=..., + smtp_username=..., + smtp_password=..., + smtp_use_tls=..., + error_subject_prefix=..., + error_message=..., + simple_html_error=..., + environ=..., +) -> None: + ... + + +@overload +def handle_exception( + exc_info, + error_stream, + html: Literal[True] = ..., + debug_mode=..., + error_email=..., + error_log=..., + show_exceptions_in_wsgi_errors=..., + error_email_from=..., + smtp_server=..., + smtp_username=..., + smtp_password=..., + smtp_use_tls=..., + error_subject_prefix=..., + error_message=..., + simple_html_error=..., + environ=..., +) -> str: + ... + + +def handle_exception( + exc_info, + error_stream, + html: bool = True, debug_mode=False, error_email=None, error_log=None,