Update the signature of decorator.decorator (#3336)

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.
This commit is contained in:
Jukka Lehtosalo
2019-10-10 16:45:06 +01:00
committed by GitHub
parent 1a932ce26a
commit eca93753ee

View File

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