-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement comparison functions for version objects `PythonVersion` and `PythonRelease`.
- Loading branch information
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
import abc | ||
|
||
|
||
class VersionLike(abc.ABC): | ||
"""Abstract class for objects that hold a version (`tuple` of `int`s) and | ||
should be comparible based on their version. | ||
""" | ||
|
||
@property | ||
@abc.abstractmethod | ||
def version_tuple(self) -> tuple[int, ...]: | ||
pass | ||
|
||
def __eq__(self, other: object) -> bool: | ||
if not isinstance(other, VersionLike): | ||
return NotImplemented | ||
return self.version_tuple == other.version_tuple | ||
|
||
def __lt__(self, other: object) -> bool: | ||
if not isinstance(other, VersionLike): | ||
return NotImplemented | ||
return self.version_tuple < other.version_tuple | ||
|
||
def __le__(self, other: object) -> bool: | ||
if not isinstance(other, VersionLike): | ||
return NotImplemented | ||
return self.version_tuple <= other.version_tuple | ||
|
||
def __gt__(self, other: object) -> bool: | ||
if not isinstance(other, VersionLike): | ||
return NotImplemented | ||
return self.version_tuple > other.version_tuple | ||
|
||
def __ge__(self, other: object) -> bool: | ||
if not isinstance(other, VersionLike): | ||
return NotImplemented | ||
return self.version_tuple >= other.version_tuple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters