Skip to content

Instantly share code, notes, and snippets.

@wasdee
Created July 6, 2023 08:26
Show Gist options
  • Save wasdee/a6d4e85169c4c17972c80582dc6d6f32 to your computer and use it in GitHub Desktop.
Save wasdee/a6d4e85169c4c17972c80582dc6d6f32 to your computer and use it in GitHub Desktop.
asynctyper
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