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