|
20 | 20 | from itertools import repeat |
21 | 21 | from types import TracebackType |
22 | 22 |
|
23 | | -import anyio |
24 | | - |
25 | 23 | from . import types |
26 | 24 | from ._utils import FLAG_NEEDS_VALUE |
27 | 25 | from ._utils import UNSET |
@@ -1540,16 +1538,31 @@ def __call__( |
1540 | 1538 | """ |
1541 | 1539 | main = self.main |
1542 | 1540 | opts: dict[str, t.Any] = {} |
1543 | | - if _anyio_backend: |
1544 | | - opts["backend"] = _anyio_backend |
1545 | | - if _anyio_backend_options: |
1546 | | - opts["backend_options"] = _anyio_backend_options |
1547 | | - return anyio.run(self.main, main, args, kwargs, **opts) # type:ignore |
| 1541 | + try: |
| 1542 | + import anyio |
| 1543 | + except ImportError: |
| 1544 | + pass |
| 1545 | + else: |
| 1546 | + if _anyio_backend: |
| 1547 | + opts["backend"] = _anyio_backend |
| 1548 | + if _anyio_backend_options: |
| 1549 | + opts["backend_options"] = _anyio_backend_options |
| 1550 | + return anyio.run(self.main, main, args, kwargs, **opts) # type:ignore |
| 1551 | + |
| 1552 | + if _anyio_backend == "trio": |
| 1553 | + import trio |
| 1554 | + |
| 1555 | + return trio.run(self._main, main, args, kwargs) |
| 1556 | + if _anyio_backend == "asyncio": |
| 1557 | + import asyncio |
| 1558 | + |
| 1559 | + return asyncio.run(self._main(main, args, kwargs)) |
| 1560 | + raise RuntimeError(f"Backend {_anyio_backend!r} unknown") |
1548 | 1561 |
|
1549 | 1562 | async def _main( |
1550 | 1563 | self, |
1551 | 1564 | main: t.Callable[..., t.Awaitable[t.Any]], |
1552 | | - args: list[t.Any], |
| 1565 | + args: t.Sequence[t.Any], |
1553 | 1566 | kwargs: dict[str, t.Any], |
1554 | 1567 | ) -> t.Any: |
1555 | 1568 | return await main(*args, **kwargs) |
|
0 commit comments