Skip to content

Commit cf2cbe2

Browse files
authored
Fix prerelease detection for > and < (#794)
1 parent a716c52 commit cf2cbe2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/packaging/specifiers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def prereleases(self) -> bool:
256256
# operators, and if they are if they are including an explicit
257257
# prerelease.
258258
operator, version = self._spec
259-
if operator in ["==", ">=", "<=", "~=", "==="]:
259+
if operator in ["==", ">=", "<=", "~=", "===", ">", "<"]:
260260
# The == specifier can include a trailing .*, if it does we
261261
# want to remove before parsing.
262262
if operator == "==" and version.endswith(".*"):

tests/test_specifiers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ def test_comparison_non_specifier(self):
328328
("2.0.post1", ">=2"),
329329
("2.0.post1.dev1", ">=2"),
330330
("3", ">=2"),
331+
("3.0.0a8", ">=3.0.0a7"),
331332
# Test the less than equal operation
332333
("2.0", "<=2"),
333334
("2.0", "<=2.0"),
@@ -341,16 +342,19 @@ def test_comparison_non_specifier(self):
341342
("2.0c1.post1.dev1", "<=2"),
342343
("2.0rc1", "<=2"),
343344
("1", "<=2"),
345+
("3.0.0a7", "<=3.0.0a8"),
344346
# Test the greater than operation
345347
("3", ">2"),
346348
("2.1", ">2.0"),
347349
("2.0.1", ">2"),
348350
("2.1.post1", ">2"),
349351
("2.1+local.version", ">2"),
352+
("3.0.0a8", ">3.0.0a7"),
350353
# Test the less than operation
351354
("1", "<2"),
352355
("2.0", "<2.1"),
353356
("2.0.dev0", "<2.1"),
357+
("3.0.0a7", "<3.0.0a8"),
354358
# Test the compatibility operation
355359
("1", "~=1.0"),
356360
("1.0.1", "~=1.0"),
@@ -519,8 +523,9 @@ def test_specifiers_identity(self, version, spec, expected):
519523
("~=1.0", False),
520524
("<1.0", False),
521525
(">1.0", False),
522-
("<1.0.dev1", False),
523-
(">1.0.dev1", False),
526+
("<1.0.dev1", True),
527+
(">1.0.dev1", True),
528+
("!=1.0.dev1", False),
524529
("==1.0.*", False),
525530
("==1.0.dev1", True),
526531
(">=1.0.dev1", True),
@@ -559,6 +564,11 @@ def test_specifiers_prereleases(self, specifier, version, expected):
559564
(">=1.0", None, ["2.0a1"], ["2.0a1"]),
560565
(">=1.0.dev1", None, ["1.0", "2.0a1"], ["1.0", "2.0a1"]),
561566
(">=1.0.dev1", False, ["1.0", "2.0a1"], ["1.0"]),
567+
("!=2.0a1", None, ["1.0a2", "1.0", "2.0a1"], ["1.0"]),
568+
("==2.0a1", None, ["2.0a1"], ["2.0a1"]),
569+
(">2.0a1", None, ["2.0a1", "3.0a2", "3.0"], ["3.0a2", "3.0"]),
570+
("<2.0a1", None, ["1.0a2", "1.0", "2.0a1"], ["1.0a2", "1.0"]),
571+
("~=2.0a1", None, ["1.0", "2.0a1", "3.0a2", "3.0"], ["2.0a1"]),
562572
],
563573
)
564574
def test_specifier_filter(self, specifier, prereleases, input, expected):

0 commit comments

Comments
 (0)