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.
This commit is contained in:
Alex Hedges 2021-05-17 14:02:27 -04:00 committed by Phil Jones
parent bf982718cf
commit 8796b2a784

View file

@ -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: