|
@@ -1,5 +1,6 @@
|
|
|
from typing import Generic, TypeVar, Optional
|
|
|
from argparse import ArgumentParser, Namespace
|
|
|
+from collections.abc import Callable, Coroutine
|
|
|
import shlex
|
|
|
|
|
|
from aiosqlite.core import Connection
|
|
@@ -52,6 +53,19 @@ class DatabaseInjector(Injector[Connection]):
|
|
|
return context.database()
|
|
|
|
|
|
|
|
|
+class Lazy(Injector[Callable[[], Coroutine[None, None, Dep]]]):
|
|
|
+ def __init__(self, deferred: Injector[Dep]):
|
|
|
+ self.deferred = deferred
|
|
|
+ self._calculated = None
|
|
|
+
|
|
|
+ async def inject(self, message: Message, context: Context) -> Callable[[], Coroutine[None, None, Dep]]:
|
|
|
+ async def call():
|
|
|
+ if self._calculated is None:
|
|
|
+ self._calculated = await self.deferred.inject(message, context)
|
|
|
+ return self._calculated
|
|
|
+ return call
|
|
|
+
|
|
|
+
|
|
|
Args = ArgsInjector()
|
|
|
ArgList = ArgListSplitOn()
|
|
|
Database = DatabaseInjector()
|