Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/packaging/_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/test_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
Loading