From d42b80634f428b001510fa94f654cb8cf1ea17aa Mon Sep 17 00:00:00 2001 From: Rohan-Salwan Date: Tue, 19 Oct 2021 07:48:54 +0530 Subject: [PATCH] fix issue4297 --- CHANGES.rst | 2 ++ src/flask/scaffold.py | 9 ++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4fec7c54..598c4ada 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -24,6 +24,8 @@ Released 2021-10-04 - Fix the order of ``before_request`` and other callbacks that trigger before the view returns. They are called from the app down to the closest nested blueprint. :issue:`4229` +- Fix ``Blueprint.errorhandler`` restricts type of result function which + avoids chaining. :issue:`4297` Version 2.0.1 diff --git a/src/flask/scaffold.py b/src/flask/scaffold.py index 07ca5c65..8a87ad32 100644 --- a/src/flask/scaffold.py +++ b/src/flask/scaffold.py @@ -80,7 +80,7 @@ class Scaffold: name: str _static_folder: t.Optional[str] = None _static_url_path: t.Optional[str] = None - + T = t.TypeVar("T", t.Callable[..., t.Any], t.Any) #: JSON encoder class used by :func:`flask.json.dumps`. If a #: blueprint sets this, it will be used instead of the app's value. json_encoder: t.Optional[t.Type[JSONEncoder]] = None @@ -646,12 +646,7 @@ class Scaffold: return f @setupmethod - def errorhandler( - self, code_or_exception: t.Union[t.Type[GenericException], int] - ) -> t.Callable[ - ["ErrorHandlerCallable[GenericException]"], - "ErrorHandlerCallable[GenericException]", - ]: + def errorhandler(self, code_or_exception: t.Union[T, int]) -> T: """Register a function to handle errors by code or exception class. A decorator that is used to register a function given an