Skip to content

Allow for FiniteDatetimeRange to be considered as "half-open" #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion xocto/ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍷 We already check with _is_datetime_range that both start and end must be datetime | None. The second part of this clause is checking whether we at least have a start or an end, meaning that we'd have a half-finite range.

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)