@@ -141,7 +141,9 @@ def append(self, func: ImpactFunc):
141141 self ._data [func .haz_type ] = dict ()
142142 self ._data [func .haz_type ][func .id ] = func
143143
144- def remove_func (self , haz_type : str = None , fun_id : str | int = None ):
144+ def remove_func (
145+ self , haz_type : Optional [str ] = None , fun_id : Optional [str | int ] = None
146+ ):
145147 """Remove impact function(s) with provided hazard type and/or id.
146148 If no input provided, all impact functions are removed.
147149
@@ -174,21 +176,21 @@ def remove_func(self, haz_type: str = None, fun_id: str | int = None):
174176 self ._data = dict ()
175177
176178 @overload
177- def get_func (self , haz_type : str , fun_id : int ) -> ImpactFunc : ...
179+ def get_func (self , haz_type : str , fun_id : int | str ) -> ImpactFunc : ...
178180
179181 @overload
180182 def get_func (self , haz_type : str , fun_id : None = None ) -> list [ImpactFunc ]: ...
181183
182184 @overload
183- def get_func (self , haz_type : None , fun_id : int ) -> list [ImpactFunc ]: ...
185+ def get_func (self , haz_type : None , fun_id : int | str ) -> list [ImpactFunc ]: ...
184186
185187 @overload
186188 def get_func (
187189 self , haz_type : None = None , fun_id : None = None
188190 ) -> Dict [str , Dict [int , ImpactFunc ]]: ...
189191
190192 def get_func (
191- self , haz_type : Optional [str ] = None , fun_id : Optional [int ] = None
193+ self , haz_type : Optional [str ] = None , fun_id : Optional [int | str ] = None
192194 ) -> Union [ImpactFunc , list [ImpactFunc ], Dict [str , Dict [int , ImpactFunc ]]]:
193195 """Get ImpactFunc(s) of input hazard type and/or id.
194196 If no input provided, all impact functions are returned.
@@ -225,7 +227,7 @@ def get_func(
225227 else :
226228 return self ._data
227229
228- def get_hazard_types (self , fun_id : str | int ) -> list [str ]:
230+ def get_hazard_types (self , fun_id : Optional [ str | int ] ) -> list [str ]:
229231 """Get impact functions hazard types contained for the id provided.
230232 Return all hazard types if no input id.
231233
@@ -247,7 +249,15 @@ def get_hazard_types(self, fun_id: str | int) -> list[str]:
247249 haz_types .append (vul_haz )
248250 return haz_types
249251
250- def get_ids (self , haz_type : str = None ) -> list [int | str ]:
252+ @overload
253+ def get_ids (self , haz_type : None = None ) -> dict [str , list [str | int ]]: ...
254+
255+ @overload
256+ def get_ids (self , haz_type : str ) -> list [int | str ]: ...
257+
258+ def get_ids (
259+ self , haz_type : Optional [str ] = None
260+ ) -> dict [str , list [str | int ]] | list [int | str ]:
251261 """Get impact functions ids contained for the hazard type provided.
252262 Return all ids for each hazard type if no input hazard type.
253263
@@ -272,7 +282,9 @@ def get_ids(self, haz_type: str = None) -> list[int | str]:
272282 except KeyError :
273283 return list ()
274284
275- def size (self , haz_type : str = None , fun_id : str | int = None ) -> int :
285+ def size (
286+ self , haz_type : Optional [str ] = None , fun_id : Optional [str | int ] = None
287+ ) -> int :
276288 """Get number of impact functions contained with input hazard type and
277289 /or id. If no input provided, get total number of impact functions.
278290
@@ -295,6 +307,7 @@ def size(self, haz_type: str = None, fun_id: str | int = None) -> int:
295307 return 1
296308 if (haz_type is not None ) or (fun_id is not None ):
297309 return len (self .get_func (haz_type , fun_id ))
310+
298311 return sum (len (vul_list ) for vul_list in self .get_ids ().values ())
299312
300313 def check (self ):
@@ -316,7 +329,7 @@ def check(self):
316329 )
317330 vul .check ()
318331
319- def extend (self , impact_funcs : ImpactFuncSet ):
332+ def extend (self , impact_funcs : " ImpactFuncSet" ):
320333 """Append impact functions of input ImpactFuncSet to current
321334 ImpactFuncSet. Overwrite ImpactFunc if same id and haz_type.
322335
@@ -339,7 +352,13 @@ def extend(self, impact_funcs: ImpactFuncSet):
339352 for _ , vul in vul_dict .items ():
340353 self .append (vul )
341354
342- def plot (self , haz_type : str = None , fun_id : str | int = None , axis = None , ** kwargs ):
355+ def plot (
356+ self ,
357+ haz_type : Optional [str ] = None ,
358+ fun_id : Optional [str | int ] = None ,
359+ axis = None ,
360+ ** kwargs ,
361+ ):
343362 """Plot impact functions of selected hazard (all if not provided) and
344363 selected function id (all if not provided).
345364
0 commit comments