Skip to content

Commit fe54868

Browse files
committed
fix: return None when from_versions is called with empty constraints
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 4f2bb91 commit fe54868

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/univers/version_range.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def from_versions(cls, sequence):
183183
version_obj = cls.version_class(version)
184184
constraint = VersionConstraint(comparator="=", version=version_obj)
185185
constraints.append(constraint)
186-
return cls(constraints=constraints)
186+
return cls(constraints=constraints) if constraints else None
187187

188188
def is_star(self):
189189
return len(self.constraints) == 1 and self.constraints[0].is_star()

tests/test_version_range.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ def test_AlpineLinuxVersionRange_from_versions():
220220
assert version_range == expected
221221

222222

223+
def test_VersionRange_from_versions_with_empty_constraints():
224+
sequence = []
225+
expected = None
226+
version_range = AlpineLinuxVersionRange.from_versions(sequence)
227+
assert version_range == expected
228+
229+
223230
def test_apk_in_RANGE_CLASS_BY_SCHEMES():
224231
assert RANGE_CLASS_BY_SCHEMES["apk"] is AlpineLinuxVersionRange
225232

0 commit comments

Comments
 (0)