Skip to content

Commit 031b3d5

Browse files
bjoernricksy0urself
authored andcommitted
Change: Allow Version comparison against strings
Allow to compare a version against strings. This is required to implement the verifying the current version.
1 parent dec700d commit 031b3d5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pontos/version/schemes/_pep440.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,19 @@ def from_version(cls, version: "Version") -> "PEP440Version":
149149
return cls.from_string(str(version))
150150

151151
def __eq__(self, other: Any) -> bool:
152+
if isinstance(other, str):
153+
# allow to compare against "current" for now
154+
return False
152155
if not isinstance(other, Version):
153156
raise ValueError(f"Can't compare {type(self)} with {type(other)}")
154157
if not isinstance(other, type(self)):
155158
other = self.from_version(other)
156159
return self._version == other._version
157160

158161
def __ne__(self, other: Any) -> bool:
162+
if isinstance(other, str):
163+
# allow to compare against "current" for now
164+
return True
159165
if not isinstance(other, Version):
160166
raise ValueError(f"Can't compare {type(self)} with {type(other)}")
161167
if not isinstance(other, type(self)):

pontos/version/schemes/_semantic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def patch(self) -> int:
116116
return self._version_info.patch
117117

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

126129
def __ne__(self, other: Any) -> bool:
130+
if isinstance(other, str):
131+
# allow to compare against "current" for now
132+
return True
127133
if not isinstance(other, Version):
128134
raise ValueError(f"Can't compare {type(self)} with {type(other)}")
129135
if not isinstance(other, type(self)):

0 commit comments

Comments
 (0)