From 4ad170b3caf1b9fe56c560b996f3a03dcb8bf4c9 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Wed, 9 Oct 2019 14:52:39 +0100 Subject: [PATCH 1/3] Fix the signature of decorator.contextmanager It must return a context manager, similar to `contextlib.contextmanager`. --- third_party/2and3/decorator.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/third_party/2and3/decorator.pyi b/third_party/2and3/decorator.pyi index 18c919f87ddd..373789c473b1 100644 --- a/third_party/2and3/decorator.pyi +++ b/third_party/2and3/decorator.pyi @@ -3,6 +3,7 @@ from typing import Any, Callable, Dict, List, NamedTuple, Optional, Pattern, Tex _C = TypeVar("_C", bound=Callable[..., Any]) _Func = TypeVar("_Func", bound=Callable[..., Any]) +_T = TypeVar("_T") def get_init(cls): ... @@ -79,5 +80,5 @@ def decorator(caller: Callable[..., Any], _func: Optional[Callable[..., Any]] = class ContextManager(_GeneratorContextManager[Any]): def __call__(self, func: _C) -> _C: ... -def contextmanager(func: _C) -> _C: ... +def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ... def dispatch_on(*dispatch_args: Any) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ... From 1949bf218a24ac9d599e11ec658dc6935beeec87 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Wed, 9 Oct 2019 15:19:36 +0100 Subject: [PATCH 2/3] Fix missing import --- 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 373789c473b1..d2106ed40324 100644 --- a/third_party/2and3/decorator.pyi +++ b/third_party/2and3/decorator.pyi @@ -1,5 +1,5 @@ import sys -from typing import Any, Callable, Dict, List, NamedTuple, Optional, Pattern, Text, Tuple, TypeVar +from typing import Any, Callable, Dict, Iterator, List, NamedTuple, Optional, Pattern, Text, Tuple, TypeVar _C = TypeVar("_C", bound=Callable[..., Any]) _Func = TypeVar("_Func", bound=Callable[..., Any]) From 2e0ddf93e8b7b8d0cdfb9e4045b83a84bc03e96c Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Wed, 9 Oct 2019 15:26:01 +0100 Subject: [PATCH 3/3] Use decorator.ContextManager --- third_party/2and3/decorator.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/2and3/decorator.pyi b/third_party/2and3/decorator.pyi index d2106ed40324..ee090a6b9d68 100644 --- a/third_party/2and3/decorator.pyi +++ b/third_party/2and3/decorator.pyi @@ -77,8 +77,8 @@ class FunctionMaker(object): def decorate(func: _Func, caller: Callable[..., Any], extras: Any = ...) -> _Func: ... def decorator(caller: Callable[..., Any], _func: Optional[Callable[..., Any]] = ...) -> Callable[[_C], _C]: ... -class ContextManager(_GeneratorContextManager[Any]): +class ContextManager(_GeneratorContextManager[_T]): def __call__(self, func: _C) -> _C: ... -def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ... +def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ... def dispatch_on(*dispatch_args: Any) -> Callable[[Callable[..., Any]], Callable[..., Any]]: ...