Skip to content

Commit 0b6a64b

Browse files
dimblebyabn
authored andcommitted
fix != version constraint incorrectly excluding pre/post/dev releases
1 parent bba3d83 commit 0b6a64b

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

src/poetry/core/constraints/version/version_union.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,7 @@ def has_upper_bound(self) -> bool:
100100

101101
def allows(self, version: Version) -> bool:
102102
if self.excludes_single_version:
103-
# when excluded version is local, special handling is required
104-
# to ensure that a constraint (!=2.0+deadbeef) will allow the
105-
# provided version (2.0)
106-
107-
excluded = self._excluded_single_version
108-
109-
if excluded.is_local():
110-
return excluded != version
103+
return not self._excluded_single_version.allows(version)
111104

112105
return any(constraint.allows(version) for constraint in self._ranges)
113106

tests/constraints/version/test_version_range.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,14 @@ def test_union(
430430
("2.0.1", "!=2.0"),
431431
("2.0.1", "!=2.0.0"),
432432
("2.0", "!=2.0+deadbeef"),
433+
# != must not inherit exclusive ordered comparison rules from < and >
434+
# (pre-releases, post-releases, dev-releases of the specified
435+
# version are not equal to it)
436+
("2.0.dev1", "!=2"),
437+
("2.0a1", "!=2"),
438+
("2.0b1", "!=2"),
439+
("2.0rc1", "!=2"),
440+
("2.0.post1", "!=2"),
433441
# Test the in-equality operation with a prefix
434442
("2.0", "!=3.*"),
435443
("2.1", "!=2.0.*"),
@@ -581,25 +589,10 @@ def test_specifiers(version: str, spec: str, expected: bool) -> None:
581589
https://github.com/pypa/packaging/blob/8b86d85797b9f26d98ecfbe0271ce4dc9495d98c/tests/test_specifiers.py#L469
582590
"""
583591
constraint = parse_constraint(spec)
584-
585592
v = Version.parse(version)
586593

587-
if expected:
588-
# Test that the plain string form works
589-
# assert version in spec
590-
assert constraint.allows(v)
591-
592-
# Test that the version instance form works
593-
# assert version in spec
594-
assert constraint.allows(v)
595-
else:
596-
# Test that the plain string form works
597-
# assert version not in spec
598-
assert not constraint.allows(v)
599-
600-
# Test that the version instance form works
601-
# assert version not in spec
602-
assert not constraint.allows(v)
594+
allowed = constraint.allows(v)
595+
assert allowed is expected
603596

604597

605598
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)