@@ -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