|
5 | 5 | Any,
|
6 | 6 | Dict,
|
7 | 7 | Final,
|
8 |
| - Generic, |
9 | 8 | List,
|
10 | 9 | Mapping,
|
11 | 10 | Optional,
|
|
26 | 25 | parse_api_date,
|
27 | 26 | parse_api_date_or_week,
|
28 | 27 | parse_api_week,
|
| 28 | + parse_user_date_or_week, |
29 | 29 | )
|
30 | 30 |
|
31 | 31 | EpiDateLike = Union[int, str, date, Week]
|
|
34 | 34 | EpiRangeParam = Union[EpiRangeLike, Sequence[EpiRangeLike]]
|
35 | 35 | StringParam = Union[str, Sequence[str]]
|
36 | 36 | IntParam = Union[int, Sequence[int]]
|
37 |
| -EpiDataResponse = TypedDict("EpiDataResponse", {"result": int, "message": str, "epidata": List}) |
38 | 37 | ParamType = Union[StringParam, IntParam, EpiRangeParam]
|
39 |
| -EPI_RANGE_TYPE = TypeVar("EPI_RANGE_TYPE", int, date, str, Week) |
| 38 | +EpiDataResponse = TypedDict("EpiDataResponse", {"result": int, "message": str, "epidata": List}) |
40 | 39 | CALL_TYPE = TypeVar("CALL_TYPE")
|
41 | 40 |
|
42 | 41 |
|
@@ -70,20 +69,15 @@ def format_list(values: EpiRangeParam) -> str:
|
70 | 69 | return format_item(values)
|
71 | 70 |
|
72 | 71 |
|
73 |
| -def format_epiweek(value: Union[str, int]) -> str: |
74 |
| - return Week.fromstring(str(value)).cdcformat() |
75 |
| - |
76 |
| - |
77 |
| -@dataclass(repr=False) |
78 |
| -class EpiRange(Generic[EPI_RANGE_TYPE]): |
| 72 | +class EpiRange: |
79 | 73 | """
|
80 | 74 | Range object for dates/epiweeks
|
81 | 75 | """
|
82 | 76 |
|
83 |
| - start: EPI_RANGE_TYPE |
84 |
| - end: EPI_RANGE_TYPE |
85 |
| - |
86 |
| - def __post_init__(self) -> None: |
| 77 | + def __init__(self, start: EpiDateLike, end: EpiDateLike) -> None: |
| 78 | + # check if types are correct |
| 79 | + self.start = parse_user_date_or_week(start) |
| 80 | + self.end = parse_user_date_or_week(end) |
87 | 81 | # swap if wrong order
|
88 | 82 | # complicated construct for typing inference
|
89 | 83 | if self.end < self.start:
|
|
0 commit comments