|
| 1 | +# Copyright 2020-present Michael Hall |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Type assertions for the more involed type transformations in the library.""" |
| 16 | + |
| 17 | +from __future__ import annotations |
| 18 | + |
| 19 | +import asyncio |
| 20 | +from collections.abc import AsyncGenerator, Coroutine, Generator |
| 21 | +from typing import Any, assert_type |
| 22 | + |
| 23 | +from async_utils.corofunc_cache import lrucorocache |
| 24 | +from async_utils.gen_transform import sync_to_async_gen_noctx |
| 25 | +from async_utils.task_cache import lrutaskcache |
| 26 | + |
| 27 | + |
| 28 | +@lrutaskcache(ttl=60, maxsize=512) |
| 29 | +async def t1(a: int, b: str, *, x: bytes) -> str: ... |
| 30 | + |
| 31 | + |
| 32 | +assert_type(t1(1, "a", x=b""), asyncio.Task[str]) |
| 33 | + |
| 34 | + |
| 35 | +@lrucorocache(ttl=60, maxsize=512) |
| 36 | +async def t2(a: int, b: str, *, x: bytes) -> str: ... |
| 37 | + |
| 38 | + |
| 39 | +_ = assert_type(t2(1, "a", x=b""), Coroutine[Any, Any, str]) |
| 40 | + |
| 41 | + |
| 42 | +def gen() -> Generator[int]: |
| 43 | + yield from range(10) |
| 44 | + |
| 45 | + |
| 46 | +_ = assert_type(sync_to_async_gen_noctx(gen), AsyncGenerator[int]) |
0 commit comments