@@ -610,13 +610,16 @@ def __eq__(self, other: int | str | Timecode | object) -> bool:
610610 bool: True if the other is equal to this Timecode instance.
611611 """
612612 if isinstance (other , Timecode ):
613- return self .framerate == other .framerate and self .frames == other .frames
613+ if self .framerate != other .framerate :
614+ raise ValueError ("'==' not supported between instances of "
615+ "'Timecode' with different framerates" )
616+ return self .frames == other .frames
614617 if isinstance (other , str ):
615618 new_tc = Timecode (self .framerate , other )
616619 return self .__eq__ (new_tc )
617620 if isinstance (other , int ):
618621 return self .frames == other
619- return False
622+ return NotImplemented
620623
621624 def __ge__ (self , other : int | str | Timecode | object ) -> bool :
622625 """Override greater than or equal to operator.
@@ -632,16 +635,16 @@ def __ge__(self, other: int | str | Timecode | object) -> bool:
632635 instance.
633636 """
634637 if isinstance (other , Timecode ):
635- return self .framerate == other .framerate and self .frames >= other .frames
638+ if self .framerate != other .framerate :
639+ raise ValueError ("'>=' not supported between instances of "
640+ "'Timecode' with different framerates" )
641+ return self .frames >= other .frames
636642 if isinstance (other , str ):
637643 new_tc = Timecode (self .framerate , other )
638644 return self .frames >= new_tc .frames
639645 if isinstance (other , int ):
640646 return self .frames >= other
641- raise TypeError (
642- "'>=' not supported between instances of 'Timecode' and "
643- f"'{ other .__class__ .__name__ } '"
644- )
647+ return NotImplemented
645648
646649 def __gt__ (self , other : int | str | Timecode ) -> bool :
647650 """Override greater than operator.
@@ -656,16 +659,16 @@ def __gt__(self, other: int | str | Timecode) -> bool:
656659 bool: True if the other is greater than this Timecode instance.
657660 """
658661 if isinstance (other , Timecode ):
659- return self .framerate == other .framerate and self .frames > other .frames
662+ if self .framerate != other .framerate :
663+ raise ValueError ("'>' not supported between instances of "
664+ "'Timecode' with different framerates" )
665+ return self .frames > other .frames
660666 if isinstance (other , str ):
661667 new_tc = Timecode (self .framerate , other )
662668 return self .frames > new_tc .frames
663669 if isinstance (other , int ):
664670 return self .frames > other
665- raise TypeError (
666- "'>' not supported between instances of 'Timecode' and "
667- f"'{ other .__class__ .__name__ } '"
668- )
671+ return NotImplemented
669672
670673 def __le__ (self , other : int | str | Timecode | object ) -> bool :
671674 """Override less or equal to operator.
@@ -680,16 +683,16 @@ def __le__(self, other: int | str | Timecode | object) -> bool:
680683 bool: True if the other is less than or equal to this Timecode instance.
681684 """
682685 if isinstance (other , Timecode ):
683- return self .framerate == other .framerate and self .frames <= other .frames
686+ if self .framerate != other .framerate :
687+ raise ValueError ("'<=' not supported between instances of "
688+ "'Timecode' with different framerates" )
689+ return self .frames <= other .frames
684690 if isinstance (other , str ):
685691 new_tc = Timecode (self .framerate , other )
686692 return self .frames <= new_tc .frames
687693 if isinstance (other , int ):
688694 return self .frames <= other
689- raise TypeError (
690- "'<' not supported between instances of 'Timecode' and "
691- f"'{ other .__class__ .__name__ } '"
692- )
695+ return NotImplemented
693696
694697 def __lt__ (self , other : int | str | Timecode ) -> bool :
695698 """Override less than operator.
@@ -704,16 +707,16 @@ def __lt__(self, other: int | str | Timecode) -> bool:
704707 bool: True if the other is less than this Timecode instance.
705708 """
706709 if isinstance (other , Timecode ):
710+ if self .framerate != other .framerate :
711+ raise ValueError ("'<' not supported between instances of "
712+ "'Timecode' with different framerates" )
707713 return self .framerate == other .framerate and self .frames < other .frames
708714 if isinstance (other , str ):
709715 new_tc = Timecode (self .framerate , other )
710716 return self .frames < new_tc .frames
711717 if isinstance (other , int ):
712718 return self .frames < other
713- raise TypeError (
714- "'<=' not supported between instances of 'Timecode' and "
715- f"'{ other .__class__ .__name__ } '"
716- )
719+ return NotImplemented
717720
718721 def __add__ (self , other : int | Timecode ) -> Timecode :
719722 """Return a new Timecode with the given timecode or frames added to this one.
@@ -737,9 +740,7 @@ def __add__(self, other: int | Timecode) -> Timecode:
737740 elif isinstance (other , int ):
738741 tc .add_frames (other )
739742 else :
740- raise TimecodeError (
741- f"Type { other .__class__ .__name__ } not supported for arithmetic."
742- )
743+ return NotImplemented
743744
744745 return tc
745746
@@ -761,9 +762,7 @@ def __sub__(self, other: int | Timecode) -> Timecode:
761762 elif isinstance (other , int ):
762763 subtracted_frames = self .frames - other
763764 else :
764- raise TimecodeError (
765- f"Type { other .__class__ .__name__ } not supported for arithmetic."
766- )
765+ return NotImplemented
767766 tc = Timecode (self .framerate , frames = abs (subtracted_frames ))
768767 tc .drop_frame = self .drop_frame
769768 return tc
@@ -786,9 +785,7 @@ def __mul__(self, other: int | Timecode) -> Timecode:
786785 elif isinstance (other , int ):
787786 multiplied_frames = self .frames * other
788787 else :
789- raise TimecodeError (
790- f"Type { other .__class__ .__name__ } not supported for arithmetic."
791- )
788+ return NotImplemented
792789 tc = Timecode (self .framerate , frames = multiplied_frames )
793790 tc .drop_frame = self .drop_frame
794791 return tc
@@ -811,9 +808,7 @@ def __div__(self, other: int | Timecode) -> Timecode:
811808 elif isinstance (other , int ):
812809 div_frames = int (float (self .frames ) / float (other ))
813810 else :
814- raise TimecodeError (
815- f"Type { other .__class__ .__name__ } not supported for arithmetic."
816- )
811+ return NotImplemented
817812
818813 return Timecode (self .framerate , frames = div_frames )
819814
0 commit comments