From 9c6b29b1793f5be0499fb8069b3ba9b7bbe89536 Mon Sep 17 00:00:00 2001 From: Alexander Fedotov Date: Fri, 16 May 2025 13:42:06 +0100 Subject: [PATCH] Allow for `FiniteDatetimeRange` to be considered as "half-open" --- xocto/ranges.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xocto/ranges.py b/xocto/ranges.py index 1f7bb6b..79ff1cb 100644 --- a/xocto/ranges.py +++ b/xocto/ranges.py @@ -1200,7 +1200,14 @@ def _is_datetime_range(value: Any) -> bool: ) +def _is_datetime_range_and_bounded(value: Any) -> bool: + return _is_datetime_range(value) and ( + isinstance(value.start, datetime.datetime) + or isinstance(value.end, datetime.datetime) + ) + + # Subscripted generics may not be used with isinstance directly. # TODO: A TypeGuard would be nicer, once we drop Python 3.9. def _is_half_finite_datetime_range(value: Any) -> bool: - return _is_datetime_range(value) and isinstance(value, HalfFiniteRange) + return _is_datetime_range_and_bounded(value) or isinstance(value, HalfFiniteRange)