Skip to content

Commit d431527

Browse files
authored
Fix a version comparison of public version with local version zero (#920)
1 parent 240a368 commit d431527

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/poetry/core/version/pep440/version.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,24 @@ class AlwaysSmaller:
2626
def __lt__(self, other: object) -> bool:
2727
return True
2828

29+
def __eq__(self, other: object) -> bool:
30+
return isinstance(other, AlwaysSmaller)
31+
32+
def __hash__(self) -> int:
33+
return id(AlwaysSmaller)
34+
2935

3036
@functools.total_ordering
3137
class AlwaysGreater:
3238
def __gt__(self, other: object) -> bool:
3339
return True
3440

41+
def __eq__(self, other: object) -> bool:
42+
return isinstance(other, AlwaysGreater)
43+
44+
def __hash__(self) -> int:
45+
return id(AlwaysGreater)
46+
3547

3648
class Infinity(AlwaysGreater, int):
3749
pass

tests/version/pep440/test_version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,16 @@ def test_without_postrelease(version: str, expected: str) -> None:
528528
def test_without_devrelease(version: str, expected: str) -> None:
529529
v = PEP440Version.parse(version)
530530
assert v.without_devrelease().text == expected
531+
532+
533+
def test_local_version_ordering_and_equality() -> None:
534+
"""PEP 440: versions with a local segment must sort after the same
535+
version without one, and they must not compare equal.
536+
"""
537+
v_plain = PEP440Version.parse("1.0")
538+
v_local = PEP440Version.parse("1.0+0")
539+
540+
# 1.0+0 must be greater than 1.0 (local versions sort after)
541+
assert v_local > v_plain
542+
# They must not be equal
543+
assert v_plain != v_local

0 commit comments

Comments
 (0)