From e850bf2e78868568417cec5b4551899621d5ac32 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 10 Oct 2019 16:14:18 +0100 Subject: [PATCH] Update the signature of decorator.decorator Nothing prevents a decorator defined using `@decorator` from changing the signature of the decorated function. For example, this example changes the return type to `str`: ``` from decorator import decorator @decorator def stringify(f, *args, **kwargs) -> str: return str(f(*args, **kwargs)) ``` The old signature caused false positives in internal Dropbox code. I couldn't come up with a signature that would produce better types with mypy while not generating false positives. --- third_party/2and3/decorator.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/2and3/decorator.pyi b/third_party/2and3/decorator.pyi index ee090a6b9d68..3443cd78b8d0 100644 --- a/third_party/2and3/decorator.pyi +++ b/third_party/2and3/decorator.pyi @@ -75,7 +75,7 @@ class FunctionMaker(object): ) -> Callable[..., Any]: ... def decorate(func: _Func, caller: Callable[..., Any], extras: Any = ...) -> _Func: ... -def decorator(caller: Callable[..., Any], _func: Optional[Callable[..., Any]] = ...) -> Callable[[_C], _C]: ... +def decorator(caller: Callable[..., Any], _func: Optional[Callable[..., Any]] = ...) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ... class ContextManager(_GeneratorContextManager[_T]): def __call__(self, func: _C) -> _C: ...