forked from orbit-oss/flask
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:
parent
bf982718cf
commit
8796b2a784
1 changed files with 4 additions and 2 deletions
|
|
@ -33,8 +33,10 @@ if t.TYPE_CHECKING:
|
||||||
# a singleton sentinel value for parameter defaults
|
# a singleton sentinel value for parameter defaults
|
||||||
_sentinel = object()
|
_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
|
"""Wraps a method so that it performs a check in debug mode if the
|
||||||
first request was already handled.
|
first request was already handled.
|
||||||
"""
|
"""
|
||||||
|
|
@ -53,7 +55,7 @@ def setupmethod(f: t.Callable) -> t.Callable:
|
||||||
)
|
)
|
||||||
return f(self, *args, **kwargs)
|
return f(self, *args, **kwargs)
|
||||||
|
|
||||||
return update_wrapper(wrapper_func, f)
|
return t.cast(F, update_wrapper(wrapper_func, f))
|
||||||
|
|
||||||
|
|
||||||
class Scaffold:
|
class Scaffold:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue