From c99d759ad36f214304b48acf59c607a3a0cf28e2 Mon Sep 17 00:00:00 2001 From: Igor Kozyrenko Date: Sun, 10 Sep 2023 12:25:37 -0700 Subject: [PATCH] fix: type check in equality operator, no comparison should raise now --- srt.py | 2 +- tests/test_srt.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/srt.py b/srt.py index c1709ee..905e334 100755 --- a/srt.py +++ b/srt.py @@ -126,7 +126,7 @@ def __hash__(self): return hash(frozenset(vars(self).items())) def __eq__(self, other): - return other and vars(self) == vars(other) + return isinstance(other, Subtitle) and vars(self) == vars(other) def __lt__(self, other): return (self.start, self.end, self.index) < ( diff --git a/tests/test_srt.py b/tests/test_srt.py index 6414e3e..5e403c4 100644 --- a/tests/test_srt.py +++ b/tests/test_srt.py @@ -242,8 +242,9 @@ def test_subtitle_inequality(sub_1): @given(subtitles()) -def test_subtitle_inequality_to_none(sub_1): +def test_subtitle_inequality_to_non_matching_type(sub_1): assert sub_1 != None + assert sub_1 != 1 @given(subtitles())