|
3 | 3 |
|
4 | 4 | import re as _re |
5 | 5 | import string as _string |
| 6 | +import asyncio as _asyncio |
6 | 7 | import inspect as _inspect |
7 | | -from typing import ( |
8 | | - Any as _Any, Set as _Set, Dict as _Dict, List as _List, Tuple as _Tuple, Union as |
9 | | - _Union, Callable as _Callable, Optional as _Optional, Coroutine as _Coroutine, |
10 | | - OrderedDict as _OrderedDict |
11 | | -) |
| 8 | +from typing import (Any as _Any, Set as _Set, Dict as _Dict, List as _List, |
| 9 | + Tuple as _Tuple, Union as _Union, Callable as _Callable, |
| 10 | + Optional as _Optional, Awaitable as _Awaitable, |
| 11 | + Coroutine as _Coroutine, OrderedDict as _OrderedDict) |
12 | 12 | from dataclasses import field as _field, dataclass as _dataclass |
13 | 13 |
|
14 | 14 | from docstring_parser import Docstring as _Docstring, parse as _parse |
@@ -151,7 +151,7 @@ class FunctionInfo: |
151 | 151 | """Represents a function.""" |
152 | 152 | function: Callable |
153 | 153 | name: str = _field(init=False) |
154 | | - arguments: _Dict[str, Argument] = _field(init=False) |
| 154 | + arguments: _OrderedDict[str, Argument] = _field(init=False) |
155 | 155 | docstring: _Docstring = _field(init=False) |
156 | 156 | parser: _Argparse.ColorizingArgumentParser = _field(init=False) |
157 | 157 |
|
@@ -313,7 +313,10 @@ def _argumentify_one(func: Callable): |
313 | 313 | args.extend(getattr(cli_args, argument.name) or []) |
314 | 314 | else: |
315 | 315 | kwargs[argument.name] = getattr(cli_args, argument.name) |
316 | | - func(*args, **kwargs) |
| 316 | + result = func(*args, **kwargs) |
| 317 | + # Check if the result is a coroutine |
| 318 | + if isinstance(result, (_Coroutine, _Awaitable)): |
| 319 | + _asyncio.run(result) |
317 | 320 |
|
318 | 321 |
|
319 | 322 | def _argumentify(functions: _Dict[str, Callable]): |
@@ -359,7 +362,10 @@ def _argumentify(functions: _Dict[str, Callable]): |
359 | 362 | args.extend(getattr(cli_args, argument.name) or []) |
360 | 363 | else: |
361 | 364 | kwargs[argument.name] = getattr(cli_args, argument.name) |
362 | | - function(*args, **kwargs) |
| 365 | + result = function(*args, **kwargs) |
| 366 | + # Check if the result is a coroutine |
| 367 | + if isinstance(result, (_Coroutine, _Awaitable)): |
| 368 | + _asyncio.run(result) |
363 | 369 |
|
364 | 370 |
|
365 | 371 | def argumentify(entry_point: _Union[Callable, _List[Callable], _Dict[str, Callable]]): |
|
0 commit comments