Created
July 6, 2023 08:26
-
-
Save wasdee/a6d4e85169c4c17972c80582dc6d6f32 to your computer and use it in GitHub Desktop.
asynctyper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from typing import Callable | |
import typer | |
from asyncio import run | |
class AsyncTyper(typer.Typer): | |
def async_command(self, _func: Callable = None, *args, **kwargs): | |
def decorator(async_func): | |
@wraps(async_func) | |
def sync_func(*_args, **_kwargs): | |
return run(async_func(*_args, **_kwargs)) | |
self.command(*args, **kwargs)(sync_func) | |
return async_func | |
if _func: | |
return decorator(_func) | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment