@@ -102,27 +102,25 @@ def bumped_candidate(self, other: "Version") -> bool:
102102 raise ValueError ("Cannot compare candidate versions if one of them is not a candidate." )
103103 return not self .bumped_technical (other ) and self .candidate > other .candidate
104104
105- def __lt__ (self , other : "Version" ) -> bool :
106- if not isinstance (other , Version ):
107- return NotImplemented
108- self_int = int (f"{ self .major } { self .functional } { self .technical } " )
109- other_int = int (f"{ other .major } { other .functional } { other .technical } " )
110- return (
111- self_int < other_int
112- or self_int == other_int
113- and (self .candidate is not None and (other .candidate is None or self .candidate < other .candidate ))
114- )
115-
116105 def __eq__ (self , other : object ) -> bool :
106+ if isinstance (other , Version ):
107+ return super ().__eq__ (other )
108+ if isinstance (other , str ):
109+ return str (self ) == other
110+ return NotImplemented
111+
112+ def __lt__ (self , other : "Version" ) -> bool :
113+ """
114+ This method asks: Is this (self) version older than the other version?
115+ """
117116 if not isinstance (other , Version ):
118117 return NotImplemented
119- return (
120- self .major == other .major
121- and self .functional == other .functional
122- and self .technical == other .technical
123- and self .is_candidate () == other .is_candidate ()
124- and (self .candidate is None or self .candidate == other .candidate )
125- )
118+ for attr in ["major" , "functional" , "technical" ]:
119+ if getattr (self , attr ) != getattr (other , attr ):
120+ return getattr (self , attr ) < getattr (other , attr )
121+ if self .candidate != other .candidate :
122+ return self .candidate is not None and (other .candidate is None or self .candidate < other .candidate )
123+ return False # self == other
126124
127125 def __str__ (self ) -> str :
128126 return self .tag_name
@@ -448,3 +446,4 @@ def test_version() -> None:
448446 assert Version .from_string ("v202401.1.2-rc3" , allow_candidate = True ) > Version .from_string (
449447 "v202401.1.2-rc1" , allow_candidate = True
450448 )
449+ assert Version .from_string ("v202501.2.0" ) > Version .from_string ("v202401.10.23" )
0 commit comments