minor refac

This commit is contained in:
Jörn-Michael Miehe 2023-10-26 17:48:33 +02:00
parent cdf4ce4d16
commit c92398118b
2 changed files with 13 additions and 7 deletions

View file

@ -25,12 +25,12 @@ _RESPONSE_OK = {
Params = ParamSpec("Params") Params = ParamSpec("Params")
Return = TypeVar("Return") Return = TypeVar("Return")
type _Dependable[**Params, Return] = Callable[Params, Awaitable[Return]] type DependableFn[**Params, Return] = Callable[Params, Awaitable[Return]]
@dataclass(slots=True, frozen=True) @dataclass(slots=True, frozen=True)
class Dependable(Generic[Params, Return]): class Dependable(Generic[Params, Return]):
func: _Dependable[Params, Return] func: DependableFn[Params, Return]
responses: dict = field(default_factory=lambda: _RESPONSE_OK.copy()) responses: dict = field(default_factory=lambda: _RESPONSE_OK.copy())
@ -92,13 +92,13 @@ class ListManager:
) )
@classmethod @classmethod
def from_lister_fn(cls, lister_fn: _Dependable[[], list[str]]) -> Self: def from_lister_fn(cls, lister_fn: DependableFn[[], list[str]]) -> Self:
return cls.from_lister(Dependable(lister_fn)) return cls.from_lister(Dependable(lister_fn))
def get_remote_path( def get_remote_path(
path_name: str, path_name: str,
) -> _Dependable[[], str]: ) -> DependableFn[[], str]:
async def _get_remote_path() -> str: async def _get_remote_path() -> str:
cfg = await get_config() cfg = await get_config()
return getattr(cfg, path_name) return getattr(cfg, path_name)
@ -112,7 +112,7 @@ RP_TEXT = get_remote_path("text_dir")
def get_file_lister( def get_file_lister(
rp: _Dependable[[], str], rp: DependableFn[[], str],
*, *,
re: re.Pattern[str], re: re.Pattern[str],
) -> Dependable[[], list[str]]: ) -> Dependable[[], list[str]]:

View file

@ -34,14 +34,20 @@ async def list_all_calendars(
return names return names
@router.get("/find/{prefix}") @router.get(
"/find/{prefix}",
responses=LM_CALENDARS.filter.responses,
)
async def find_calendars( async def find_calendars(
names: list[str] = Depends(LM_CALENDARS.filter.func), names: list[str] = Depends(LM_CALENDARS.filter.func),
) -> list[str]: ) -> list[str]:
return names return names
@router.get("/get/{prefix}") @router.get(
"/get/{prefix}",
responses=LM_CALENDARS.getter.responses,
)
async def get_calendar( async def get_calendar(
name: str = Depends(LM_CALENDARS.getter.func), name: str = Depends(LM_CALENDARS.getter.func),
cfg: Config = Depends(get_config), cfg: Config = Depends(get_config),