-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_mypy_decorators_pep612.py
46 lines (28 loc) · 1.09 KB
/
test_mypy_decorators_pep612.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
## https://peps.python.org/pep-0612/
from typing import Awaitable, Callable, TypeVar
import asyncio
R = TypeVar("R")
def sleep_n_run(delay: int):
def decorator(f: Callable[..., Awaitable[R]]) -> Callable[..., Awaitable[R]]:
async def inner(*args: object, **kwargs: object) -> R:
await asyncio.sleep(delay)
return await f(*args, **kwargs)
return inner
return decorator
@sleep_n_run(2)
async def takes_int_str(x: int, y: str) -> int:
return x + 7
async def test_it():
await takes_int_str(1, "A")
await takes_int_str("B", 2) # fails at runtime
with tempfile.TemporaryDirectory(prefix=f"{__name__}_") as tmpdir:
compose_path = Path(tmpdir) / "docker-compose.yml"
compose_path.write_text(yaml_content)
cmd = command.format(file_path=compose_path)
logger.info("Runs %s ...\n%s", cmd, yaml_content)
result = await async_command(
command=cmd,
timeout=process_termination_timeout,
)
logger.info("Done %s", pformat(deepcopy(result._asdict())))
return result