mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-25 04:57:54 +00:00
Remove a type: ignore comment
GIve the type checker more information about the converters instead.
This commit is contained in:
@@ -3,14 +3,14 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
import pickle # nosec:B403
|
import pickle # nosec:B403
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Any
|
from typing import Any, Callable
|
||||||
|
|
||||||
import pendulum
|
import pendulum
|
||||||
from fastapi.encoders import jsonable_encoder
|
from fastapi.encoders import jsonable_encoder
|
||||||
from starlette.responses import JSONResponse
|
from starlette.responses import JSONResponse
|
||||||
from starlette.templating import _TemplateResponse as TemplateResponse
|
from starlette.templating import _TemplateResponse as TemplateResponse
|
||||||
|
|
||||||
CONVERTERS = {
|
CONVERTERS: dict[str, Callable[[str], Any]] = {
|
||||||
"date": lambda x: pendulum.parse(x, exact=True),
|
"date": lambda x: pendulum.parse(x, exact=True),
|
||||||
"datetime": lambda x: pendulum.parse(x, exact=True),
|
"datetime": lambda x: pendulum.parse(x, exact=True),
|
||||||
"decimal": Decimal,
|
"decimal": Decimal,
|
||||||
@@ -35,7 +35,7 @@ def object_hook(obj: Any) -> Any:
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
if _spec_type in CONVERTERS:
|
if _spec_type in CONVERTERS:
|
||||||
return CONVERTERS[_spec_type](obj["val"]) # type: ignore
|
return CONVERTERS[_spec_type](obj["val"])
|
||||||
else:
|
else:
|
||||||
raise TypeError("Unknown {}".format(_spec_type))
|
raise TypeError("Unknown {}".format(_spec_type))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user