Skip to content

Commit 4d32ece

Browse files
committed
Address review comments
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent 96ac3b8 commit 4d32ece

4 files changed

Lines changed: 5296 additions & 30 deletions

File tree

src/univers/version_constraint.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ def operator_star(a, b):
3939
return True
4040

4141

42-
def operator_null(a, b):
43-
"""
44-
Comparison operator for the star "^" constraint comparator. Since it does not matches
45-
any version, it is always False.
46-
"""
47-
return False
48-
49-
5042
# note: ORDER MATTER here: we tests startswith(key) for each key in sequence
5143
COMPARATORS = {
5244
">=": operator.ge,
@@ -56,7 +48,6 @@ def operator_null(a, b):
5648
">": operator.gt,
5749
"=": operator.eq,
5850
"*": operator_star,
59-
"^": operator_null,
6051
}
6152

6253

@@ -159,10 +150,10 @@ def from_string(cls, string, version_class):
159150
if comparator not in COMPARATORS:
160151
raise ValueError(f"Unknown comparator: {comparator!r}")
161152

162-
if not version and comparator not in ["*", "^"]:
153+
if not version and comparator != "*":
163154
raise ValueError("Empty version")
164155

165-
if comparator in ["*", "^"]:
156+
if comparator == "*":
166157
version = None
167158
else:
168159
version = version_class(version)

src/univers/version_range.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class InvalidVersionRange(Exception):
3232
"<": ">=",
3333
">": "<=",
3434
"=": "!=",
35-
"*": "^",
36-
"^": "*",
3735
}
3836

3937

@@ -176,30 +174,30 @@ def from_versions(cls, sequence):
176174
constraints.append(constraint)
177175
return cls(constraints=constraints)
178176

179-
def inverse(self):
177+
def invert(self):
180178
"""
181179
Return the inverse of this VersionRange. For example, if this range is
182180
">=1.0.0", the inverse is "<1.0.0".
183181
>>> VersionRange.from_string("vers:npm/>=1.0.0").inverse()
184182
NpmVersionRange(constraints=(VersionConstraint(comparator='<', version=SemverVersion(string='1.0.0')),))
185183
"""
186184
inverted_constraints = []
185+
186+
if len(self.constraints) == 1 and self.constraints[0].comparator == "*":
187+
# The inverse of "*" is an empty range.
188+
return None
189+
187190
for constraint in self.constraints:
188191
if constraint.comparator in INVERTED_COMPARATORS:
189192
inverted_comparator = INVERTED_COMPARATORS[constraint.comparator]
190193
else:
191194
raise NotImplementedError(
192195
f"Cannot invert a range with a {constraint.comparator!r} comparator."
193196
)
194-
if inverted_comparator == "*" or inverted_comparator == "^":
195-
inverted_constraint = VersionConstraint.from_string(
196-
string=inverted_comparator, version_class=self.version_class
197-
)
198-
else:
199-
inverted_constraint = VersionConstraint(
200-
comparator=inverted_comparator,
201-
version=constraint.version,
202-
)
197+
inverted_constraint = VersionConstraint(
198+
comparator=inverted_comparator,
199+
version=constraint.version,
200+
)
203201
inverted_constraints.append(inverted_constraint)
204202
return self.__class__(constraints=inverted_constraints)
205203

0 commit comments

Comments
 (0)