Skip to content

Commit d40c711

Browse files
committed
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.
1 parent 2b00491 commit d40c711

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

pystac/collection.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,10 @@ class TemporalExtent:
151151
Datetimes are required to be in UTC.
152152
"""
153153

154-
def __init__(
155-
self, intervals: Union[List[List[Optional[Datetime]]], List[Optional[Datetime]]]
156-
):
157-
# A common mistake is to pass in a single interval instead of a
158-
# list of intervals. Account for this by transforming the input
159-
# in that case.
160-
if isinstance(intervals, list) and isinstance(intervals[0], Datetime):
161-
self.intervals = [cast(List[Optional[Datetime]], intervals)]
162-
else:
163-
self.intervals = cast(List[List[Optional[Datetime]]], intervals)
154+
def __init__(self, intervals: List[List[Optional[Datetime]]]):
155+
assert isinstance(intervals, list)
156+
assert isinstance(intervals[0], list)
157+
self.intervals = intervals
164158

165159
def to_dict(self) -> Dict[str, Any]:
166160
"""Generate a dictionary representing the JSON of this TemporalExtent.

0 commit comments

Comments
 (0)