From 27310fc68e3264c608c95840868b7389ffa7dabc Mon Sep 17 00:00:00 2001 From: Leon Haffmans Date: Fri, 21 Mar 2025 10:58:46 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=A9=B9version=20checker=20on=20releas?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/compatibility/versioning.py | 34 +++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/docs/compatibility/versioning.py b/docs/compatibility/versioning.py index e94e2dc43..54410eda2 100644 --- a/docs/compatibility/versioning.py +++ b/docs/compatibility/versioning.py @@ -102,27 +102,25 @@ def bumped_candidate(self, other: "Version") -> bool: raise ValueError("Cannot compare candidate versions if one of them is not a candidate.") return not self.bumped_technical(other) and self.candidate > other.candidate - def __lt__(self, other: "Version") -> bool: - if not isinstance(other, Version): - return NotImplemented - self_int = int(f"{self.major}{self.functional}{self.technical}") - other_int = int(f"{other.major}{other.functional}{other.technical}") - return ( - self_int < other_int - or self_int == other_int - and (self.candidate is not None and (other.candidate is None or self.candidate < other.candidate)) - ) - def __eq__(self, other: object) -> bool: + if isinstance(other, Version): + return super().__eq__(other) + if isinstance(other, str): + return str(self) == other + return NotImplemented + + def __lt__(self, other: "Version") -> bool: + """ + This method asks: Is this (self) version older than the other version? + """ if not isinstance(other, Version): return NotImplemented - return ( - self.major == other.major - and self.functional == other.functional - and self.technical == other.technical - and self.is_candidate() == other.is_candidate() - and (self.candidate is None or self.candidate == other.candidate) - ) + for attr in ["major", "functional", "technical"]: + if getattr(self, attr) != getattr(other, attr): + return getattr(self, attr) < getattr(other, attr) + if self.candidate != other.candidate: + return self.candidate is not None and (other.candidate is None or self.candidate < other.candidate) + return False # self == other def __str__(self) -> str: return self.tag_name From 1a63dd70677fc8690e63ddb2a212fd00c89718db Mon Sep 17 00:00:00 2001 From: Leon Haffmans Date: Fri, 21 Mar 2025 10:59:17 +0100 Subject: [PATCH 2/2] Add a test case --- docs/compatibility/versioning.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/compatibility/versioning.py b/docs/compatibility/versioning.py index 54410eda2..acb62db82 100644 --- a/docs/compatibility/versioning.py +++ b/docs/compatibility/versioning.py @@ -446,3 +446,4 @@ def test_version() -> None: assert Version.from_string("v202401.1.2-rc3", allow_candidate=True) > Version.from_string( "v202401.1.2-rc1", allow_candidate=True ) + assert Version.from_string("v202501.2.0") > Version.from_string("v202401.10.23")