Skip to content

Commit 9b086f4

Browse files
committed
Tell typecheckers that Promise is a context manager
1 parent 02bdfe2 commit 9b086f4

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

invoke/runners.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import threading
88
import time
9+
from contextlib import AbstractContextManager
910
from subprocess import PIPE, Popen
1011
from types import TracebackType
1112
from typing import (
@@ -1614,7 +1615,7 @@ def tail(self, stream: str, count: int = 10) -> str:
16141615
return "\n\n" + "\n".join(getattr(self, stream).splitlines()[-count:])
16151616

16161617

1617-
class Promise(Result):
1618+
class Promise(Result, AbstractContextManager):
16181619
"""
16191620
A promise of some future `Result`, yielded from asynchronous execution.
16201621

tests/runners.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import termios
77
import threading
88
import types
9+
from contextlib import AbstractContextManager
910
from io import BytesIO, StringIO
1011
from itertools import chain, repeat
1112
from unittest.mock import Mock, call, patch
@@ -1825,6 +1826,10 @@ def works_for_stderr_too(self):
18251826

18261827

18271828
class Promise_:
1829+
def explicitly_inherits_from_abstract_base_class(self) -> None:
1830+
# Supports improved downstream typechecking.
1831+
assert AbstractContextManager in Promise.__mro__
1832+
18281833
def exposes_read_only_run_params(self):
18291834
runner = _runner()
18301835
promise = runner.run(

0 commit comments

Comments
 (0)