Skip to content

Commit 958f589

Browse files
committed
Better type hints
1 parent 185957a commit 958f589

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

climada/entity/impact_funcs/impact_func_set.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import copy
2525
import logging
2626
from itertools import repeat
27-
from typing import Iterable, Optional
27+
from typing import Dict, Iterable, Optional, Union, overload
2828

2929
import matplotlib.pyplot as plt
3030
import numpy as np
@@ -173,7 +173,23 @@ def remove_func(self, haz_type=None, fun_id=None):
173173
else:
174174
self._data = dict()
175175

176-
def get_func(self, haz_type=None, fun_id=None):
176+
@overload
177+
def get_func(self, haz_type: str, fun_id: int) -> ImpactFunc: ...
178+
179+
@overload
180+
def get_func(self, haz_type: str, fun_id: None = None) -> list[ImpactFunc]: ...
181+
182+
@overload
183+
def get_func(self, haz_type: None, fun_id: int) -> list[ImpactFunc]: ...
184+
185+
@overload
186+
def get_func(
187+
self, haz_type: None = None, fun_id: None = None
188+
) -> Dict[str, Dict[int, ImpactFunc]]: ...
189+
190+
def get_func(
191+
self, haz_type: Optional[str] = None, fun_id: Optional[int] = None
192+
) -> Union[ImpactFunc, list[ImpactFunc], Dict[str, Dict[int, ImpactFunc]]]:
177193
"""Get ImpactFunc(s) of input hazard type and/or id.
178194
If no input provided, all impact functions are returned.
179195

0 commit comments

Comments
 (0)