From 8796b2a784bc45fcc6865cd80b2cba0601448727 Mon Sep 17 00:00:00 2001 From: Alex Hedges Date: Mon, 17 May 2021 14:02:27 -0400 Subject: [PATCH] Use TypeVar for setupmethod() TypeVar is needed to preserve function signatures. The type cast for update_wrapper is needed because wapper_func can not use the full signature that f does. --- src/flask/scaffold.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/flask/scaffold.py b/src/flask/scaffold.py index 20654b6b..f8f94af1 100644 --- a/src/flask/scaffold.py +++ b/src/flask/scaffold.py @@ -33,8 +33,10 @@ if t.TYPE_CHECKING: # a singleton sentinel value for parameter defaults _sentinel = object() +F = t.TypeVar("F", bound=t.Callable[..., t.Any]) -def setupmethod(f: t.Callable) -> t.Callable: + +def setupmethod(f: F) -> F: """Wraps a method so that it performs a check in debug mode if the first request was already handled. """ @@ -53,7 +55,7 @@ def setupmethod(f: t.Callable) -> t.Callable: ) return f(self, *args, **kwargs) - return update_wrapper(wrapper_func, f) + return t.cast(F, update_wrapper(wrapper_func, f)) class Scaffold: