|
| 1 | +print("Testing runtime aspects of collections.abc module") |
| 2 | + |
| 3 | +try: |
| 4 | + import typing |
| 5 | +except ImportError: |
| 6 | + print("SKIP") |
| 7 | + raise SystemExit |
| 8 | + |
| 9 | + |
| 10 | +print("Testing : collections.abc.Mapping, Sequence") |
| 11 | + |
| 12 | +# FIXME: from collections.abc import Mapping, Sequence |
| 13 | +from typing import Mapping, Sequence |
| 14 | + |
| 15 | + |
| 16 | +class Employee: |
| 17 | + ... |
| 18 | + |
| 19 | + |
| 20 | +def notify_by_email(employees: Sequence[Employee], overrides: Mapping[str, str]) -> None: |
| 21 | + pass |
| 22 | + |
| 23 | + |
| 24 | +notify_by_email([], {}) |
| 25 | + |
| 26 | + |
| 27 | +print("Testing : collections.abc.Callable, Awaitable") |
| 28 | + |
| 29 | +# from collections.abc import Callable, Awaitable |
| 30 | +from typing import Callable, Awaitable |
| 31 | + |
| 32 | + |
| 33 | +def feeder(get_next_item: Callable[[], str]) -> None: |
| 34 | + ... # Body |
| 35 | + |
| 36 | + |
| 37 | +def async_query( |
| 38 | + on_success: Callable[[int], None], on_error: Callable[[int, Exception], None] |
| 39 | +) -> None: |
| 40 | + ... # Body |
| 41 | + |
| 42 | + |
| 43 | +async def on_update(value: str) -> None: |
| 44 | + ... # Body |
| 45 | + |
| 46 | + |
| 47 | +callback: Callable[[str], Awaitable[None]] = on_update |
| 48 | + |
| 49 | +# ... |
| 50 | + |
| 51 | + |
| 52 | +def concat(x: str, y: str) -> str: |
| 53 | + return x + y |
| 54 | + |
| 55 | + |
| 56 | +x: Callable[..., str] |
| 57 | +x = str # OK |
| 58 | +x = concat # Also OK |
| 59 | + |
| 60 | + |
| 61 | +print("Testing : collections.abc.Iterable") |
| 62 | + |
| 63 | +# FIXME: from collections.abc import Iterable |
| 64 | +from typing import Iterable |
| 65 | +from typing import Protocol |
| 66 | + |
| 67 | + |
| 68 | +class Combiner(Protocol): |
| 69 | + def __call__(self, *vals: bytes, maxlen: int | None = None) -> list[bytes]: |
| 70 | + ... |
| 71 | + |
| 72 | + |
| 73 | +def batch_proc(data: Iterable[bytes], cb_results: Combiner) -> bytes: |
| 74 | + for item in data: |
| 75 | + pass |
| 76 | + return b"".join(cb_results(*data)) |
| 77 | + |
| 78 | + |
| 79 | +def good_cb(*vals: bytes, maxlen: int | None = None) -> list[bytes]: |
| 80 | + return [val[:maxlen] for val in vals if maxlen is not None] |
| 81 | + |
| 82 | + |
| 83 | +batch_proc([], good_cb) # OK |
| 84 | + |
| 85 | + |
| 86 | +print("Testing : collections.abc.") |
| 87 | +print("Testing : collections.abc.") |
| 88 | +print("Testing : collections.abc.") |
0 commit comments