From f5ceb8927f2e7f2a9e29d62c8e4cef876f917249 Mon Sep 17 00:00:00 2001 From: Kyomotoi <1172294279@qq.com> Date: Sat, 6 Feb 2021 00:32:26 +0800 Subject: =?UTF-8?q?=F0=9F=8F=97=20=F0=9F=92=A9=20=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=BB=93=E6=9E=84=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=95=A5b=20BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ATRI/syncer.py | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 ATRI/syncer.py (limited to 'ATRI/syncer.py') diff --git a/ATRI/syncer.py b/ATRI/syncer.py deleted file mode 100644 index b4c59b1..0000000 --- a/ATRI/syncer.py +++ /dev/null @@ -1,47 +0,0 @@ -import sys -import asyncio -import inspect -import types -from functools import singledispatch, wraps - -from typing import Any, Callable, Generator - - -PY37 = sys.version_info >= (3, 7) - - -def _is_awaitable(co: Generator[Any, None, Any]) -> bool: - if PY37: - return inspect.isawaitable(co) - else: - return (isinstance(co, types.GeneratorType) or - isinstance(co, asyncio.Future)) - - -@singledispatch -def sync(co: Any) -> Any: - raise TypeError(f'Called with unsupported argument: {co}') - - -@sync.register(asyncio.Future) -@sync.register(types.GeneratorType) -def sync_co(co: Generator[Any, None, Any]) -> Any: - if not _is_awaitable(co): - raise TypeError(f'Called with unsupported argument: {co}') - return asyncio.get_event_loop().run_until_complete(co) - - -@sync.register(types.FunctionType) -@sync.register(types.MethodType) # type: ignore -def sync_fu(f: Callable[..., Any]) -> Callable[..., Any]: - if not asyncio.iscoroutinefunction(f): - raise TypeError(f'Called with unsupported argument: {f}') - - @wraps(f) - def run(*args, **kwargs) -> Any: - return asyncio.get_event_loop().run_until_complete(f(*args, **kwargs)) - return run - - -if PY37: - sync.register(types.CoroutineType)(sync_co) -- cgit v1.2.3