22
33import json
44from copy import copy
5- from typing import Annotated , Dict , List , Literal , Optional , Type
5+ from typing import Annotated , Literal
66
77import attr
88from fastapi import HTTPException , Query
1919from titiler .core .algorithm .math import _Max , _Mean , _Median , _Min , _Std , _Sum , _Var
2020from titiler .core .algorithm .ops import CastToInt , Ceil , Floor
2121
22- default_algorithms : Dict [str , Type [BaseAlgorithm ]] = {
22+ default_algorithms : dict [str , type [BaseAlgorithm ]] = {
2323 "hillshade" : HillShade ,
2424 "slope" : Slope ,
2525 "contours" : Contours ,
4545class Algorithms :
4646 """Algorithms."""
4747
48- data : Dict [str , Type [BaseAlgorithm ]] = attr .ib ()
48+ data : dict [str , type [BaseAlgorithm ]] = attr .ib (factory = dict )
4949
50- def get (self , name : str ) -> BaseAlgorithm :
50+ def get (self , name : str ) -> type [ BaseAlgorithm ] :
5151 """Fetch a TMS."""
5252 if name not in self .data :
5353 raise KeyError (f"Invalid name: { name } " )
5454
5555 return self .data [name ]
5656
57- def list (self ) -> List [str ]:
57+ def list (self ) -> list [str ]:
5858 """List registered Algorithm."""
5959 return list (self .data .keys ())
6060
6161 def register (
6262 self ,
63- algorithms : Dict [str , BaseAlgorithm ],
63+ algorithms : dict [str , BaseAlgorithm ],
6464 overwrite : bool = False ,
6565 ) -> "Algorithms" :
6666 """Register Algorithm(s)."""
6767 for name , _algo in algorithms .items ():
6868 if name in self .data and not overwrite :
6969 raise Exception (f"{ name } is already a registered. Use overwrite=True." )
7070
71- return Algorithms ({** self .data , ** algorithms })
71+ return Algorithms ({** self .data , ** algorithms }) # type: ignore [dict-item]
7272
7373 @property
7474 def dependency (self ):
@@ -80,10 +80,10 @@ def post_process(
8080 Query (description = "Algorithm name" ),
8181 ] = None ,
8282 algorithm_params : Annotated [
83- Optional [ str ] ,
83+ str | None ,
8484 Query (description = "Algorithm parameter" ),
8585 ] = None ,
86- ) -> Optional [ BaseAlgorithm ] :
86+ ) -> BaseAlgorithm | None :
8787 """Data Post-Processing options."""
8888 kwargs = json .loads (algorithm_params ) if algorithm_params else {}
8989 if algorithm :
0 commit comments