diff --git a/src/packaging/_structures.py b/src/packaging/_structures.py index 225e2eee..74ca8f0c 100644 --- a/src/packaging/_structures.py +++ b/src/packaging/_structures.py @@ -19,13 +19,13 @@ def __lt__(self, other: object) -> bool: return False def __le__(self, other: object) -> bool: - return False + return other is self def __eq__(self, other: object) -> bool: - return isinstance(other, self.__class__) + return other is self def __gt__(self, other: object) -> bool: - return True + return other is not self def __ge__(self, other: object) -> bool: return True @@ -48,19 +48,19 @@ def __hash__(self) -> int: return hash(repr(self)) def __lt__(self, other: object) -> bool: - return True + return other is not self def __le__(self, other: object) -> bool: return True def __eq__(self, other: object) -> bool: - return isinstance(other, self.__class__) + return other is self def __gt__(self, other: object) -> bool: return False def __ge__(self, other: object) -> bool: - return False + return other is self def __neg__(self: object) -> InfinityType: return Infinity diff --git a/tests/test_structures.py b/tests/test_structures.py index d85c9621..6b67d189 100644 --- a/tests/test_structures.py +++ b/tests/test_structures.py @@ -49,10 +49,24 @@ def test_infinity_equal() -> None: assert Infinity == Infinity +def test_infinity_self_comparison() -> None: + assert not Infinity < Infinity + assert Infinity <= Infinity + assert not Infinity > Infinity + assert Infinity >= Infinity + + def test_negative_infinity_equal() -> None: assert NegativeInfinity == NegativeInfinity +def test_negative_infinity_self_comparison() -> None: + assert not NegativeInfinity < NegativeInfinity + assert NegativeInfinity <= NegativeInfinity + assert not NegativeInfinity > NegativeInfinity + assert NegativeInfinity >= NegativeInfinity + + def test_negate_infinity() -> None: assert isinstance(-Infinity, NegativeInfinity.__class__)