Skip to content

Commit

Permalink
Verify that passed intervals are lists of lists
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
l0b0 committed May 23, 2021
1 parent 424602a commit d990ae7
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions pystac/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d990ae7

Please sign in to comment.