Skip to content

Commit d47ff68

Browse files
committed
Bail out of comparisons when conversion to comparable type fails
1 parent 1b7ee68 commit d47ff68

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/undate/undate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ def __eq__(self, other: object) -> bool:
334334

335335
def __lt__(self, other: object) -> bool:
336336
other = self._comparison_type(other)
337+
if other is NotImplemented:
338+
# return NotImplemented to indicate comparison is not supported
339+
# with this type
340+
return NotImplemented
337341

338342
# if either date has a completely unknown year, then we can't compare
339343
if self.unknown_year or other.unknown_year:
@@ -394,6 +398,10 @@ def __contains__(self, other: object) -> bool:
394398
# if the two dates are strictly equal, don't consider
395399
# either one as containing the other
396400
other = self._comparison_type(other)
401+
if other is NotImplemented:
402+
# return NotImplemented to indicate comparison is not supported
403+
# with this type
404+
return NotImplemented
397405

398406
if self == other:
399407
return False

0 commit comments

Comments
 (0)