Skip to content

Commit

Permalink
style: fix mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 20, 2024
1 parent f0dfb2d commit ed4912e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions server/tmpl.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing
from collections.abc import Callable
from datetime import datetime, timedelta
from typing import Any
Expand All @@ -16,12 +17,24 @@
auto_reload=DEV,
)

P = typing.ParamSpec("P")
T = typing.TypeVar("T")

def add_filter(s: str | Callable):
def real_wrapper(name: str, fn: Callable):

@typing.overload
def add_filter(s: str) -> Callable[[Callable[P, T]], Callable[P, T]]: ...


@typing.overload
def add_filter(s: Callable[P, T]) -> Callable[P, T]: ...


def add_filter(s: str | Callable[P, T]) -> Any:
def real_wrapper(name: str, fn: Callable[P, T]) -> Callable[P, T]:
if name in engine.filters:
raise ValueError(f"filter '{name}' already exists")
engine.filters[name] = fn
return fn

if isinstance(s, str):
return lambda fn: real_wrapper(s, fn)
Expand Down Expand Up @@ -73,7 +86,7 @@ def format_duration(seconds: timedelta) -> str:


@add_filter
def subject_type_readable(s: int):
def subject_type_readable(s: int) -> str:
match s:
case 1:
return "书籍"
Expand Down

0 comments on commit ed4912e

Please sign in to comment.