Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions docs/compatibility/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wofür ist der Kommentar?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um zu verdeutlichen, dass wir an der Stelle des Codes wissen, dass die Versionen gleich sind und dementsprechend __lt__ ein False zurückgeben muss. Ist der Kommentar nicht sprechend? ^^


def __str__(self) -> str:
return self.tag_name
Expand Down Expand Up @@ -448,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")
Loading