From d990ae7a99ff76a368fdfd7a153688e6b5e2f68b Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Mon, 24 May 2021 10:07:52 +1200 Subject: [PATCH] Verify that passed intervals are lists of lists Trying to second guess the intent of the caller made the types and implementation more complex, and had a bug: if `intervals[0]` was `None` (that is, the user had passed a single interval with an open start) rather than a `datetime` then `intervals` would wrongly be treated as a list of lists. --- pystac/collection.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pystac/collection.py b/pystac/collection.py index cf0f38c40..4aa448243 100644 --- a/pystac/collection.py +++ b/pystac/collection.py @@ -151,16 +151,10 @@ class TemporalExtent: Datetimes are required to be in UTC. """ - def __init__( - self, intervals: Union[List[List[Optional[Datetime]]], List[Optional[Datetime]]] - ): - # A common mistake is to pass in a single interval instead of a - # list of intervals. Account for this by transforming the input - # in that case. - if isinstance(intervals, list) and isinstance(intervals[0], Datetime): - self.intervals = [cast(List[Optional[Datetime]], intervals)] - else: - self.intervals = cast(List[List[Optional[Datetime]]], intervals) + def __init__(self, intervals: List[List[Optional[Datetime]]]): + assert isinstance(intervals, list) + assert isinstance(intervals[0], list) + self.intervals = intervals def to_dict(self) -> Dict[str, Any]: """Generate a dictionary representing the JSON of this TemporalExtent.