Skip to content

Commit

Permalink
Change: Allow Version comparison against strings
Browse files Browse the repository at this point in the history
Allow to compare a version against strings. This is required to
implement the verifying the current version.
  • Loading branch information
bjoernricks authored and y0urself committed Mar 14, 2023
1 parent dec700d commit 031b3d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pontos/version/schemes/_pep440.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ def from_version(cls, version: "Version") -> "PEP440Version":
return cls.from_string(str(version))

def __eq__(self, other: Any) -> bool:
if isinstance(other, str):
# allow to compare against "current" for now
return False
if not isinstance(other, Version):
raise ValueError(f"Can't compare {type(self)} with {type(other)}")
if not isinstance(other, type(self)):
other = self.from_version(other)
return self._version == other._version

def __ne__(self, other: Any) -> bool:
if isinstance(other, str):
# allow to compare against "current" for now
return True
if not isinstance(other, Version):
raise ValueError(f"Can't compare {type(self)} with {type(other)}")
if not isinstance(other, type(self)):
Expand Down
6 changes: 6 additions & 0 deletions pontos/version/schemes/_semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def patch(self) -> int:
return self._version_info.patch

def __eq__(self, other: Any) -> bool:
if isinstance(other, str):
# allow to compare against "current" for now
return False
if not isinstance(other, Version):
raise ValueError(f"Can't compare {type(self)} with {type(other)}")
if not isinstance(other, type(self)):
Expand All @@ -124,6 +127,9 @@ def __eq__(self, other: Any) -> bool:
return self._version_info == other._version_info

def __ne__(self, other: Any) -> bool:
if isinstance(other, str):
# allow to compare against "current" for now
return True
if not isinstance(other, Version):
raise ValueError(f"Can't compare {type(self)} with {type(other)}")
if not isinstance(other, type(self)):
Expand Down

0 comments on commit 031b3d5

Please sign in to comment.