minor refac
This commit is contained in:
parent
cdf4ce4d16
commit
c92398118b
2 changed files with 13 additions and 7 deletions
|
@ -25,12 +25,12 @@ _RESPONSE_OK = {
|
|||
Params = ParamSpec("Params")
|
||||
Return = TypeVar("Return")
|
||||
|
||||
type _Dependable[**Params, Return] = Callable[Params, Awaitable[Return]]
|
||||
type DependableFn[**Params, Return] = Callable[Params, Awaitable[Return]]
|
||||
|
||||
|
||||
@dataclass(slots=True, frozen=True)
|
||||
class Dependable(Generic[Params, Return]):
|
||||
func: _Dependable[Params, Return]
|
||||
func: DependableFn[Params, Return]
|
||||
responses: dict = field(default_factory=lambda: _RESPONSE_OK.copy())
|
||||
|
||||
|
||||
|
@ -92,13 +92,13 @@ class ListManager:
|
|||
)
|
||||
|
||||
@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))
|
||||
|
||||
|
||||
def get_remote_path(
|
||||
path_name: str,
|
||||
) -> _Dependable[[], str]:
|
||||
) -> DependableFn[[], str]:
|
||||
async def _get_remote_path() -> str:
|
||||
cfg = await get_config()
|
||||
return getattr(cfg, path_name)
|
||||
|
@ -112,7 +112,7 @@ RP_TEXT = get_remote_path("text_dir")
|
|||
|
||||
|
||||
def get_file_lister(
|
||||
rp: _Dependable[[], str],
|
||||
rp: DependableFn[[], str],
|
||||
*,
|
||||
re: re.Pattern[str],
|
||||
) -> Dependable[[], list[str]]:
|
||||
|
|
|
@ -34,14 +34,20 @@ async def list_all_calendars(
|
|||
return names
|
||||
|
||||
|
||||
@router.get("/find/{prefix}")
|
||||
@router.get(
|
||||
"/find/{prefix}",
|
||||
responses=LM_CALENDARS.filter.responses,
|
||||
)
|
||||
async def find_calendars(
|
||||
names: list[str] = Depends(LM_CALENDARS.filter.func),
|
||||
) -> list[str]:
|
||||
return names
|
||||
|
||||
|
||||
@router.get("/get/{prefix}")
|
||||
@router.get(
|
||||
"/get/{prefix}",
|
||||
responses=LM_CALENDARS.getter.responses,
|
||||
)
|
||||
async def get_calendar(
|
||||
name: str = Depends(LM_CALENDARS.getter.func),
|
||||
cfg: Config = Depends(get_config),
|
||||
|
|
Loading…
Reference in a new issue