Skip to content

Commit

Permalink
Fix stable sort in heapq.merge: python uses both __eq__ and __lt__ to… (
Browse files Browse the repository at this point in the history
#112)

* Fix stable sort in heapq.merge: python uses both __eq__ and __lt__ to compare tuples.

Co-authored-by: Yakov Galka <yakov@stannum.io>
  • Loading branch information
ybungalobill and Yakov Galka authored Oct 4, 2023
1 parent 5635ded commit c6742d7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions asyncstdlib/heapq.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ async def pull_head(self) -> bool:
def __lt__(self, other: "_KeyIter[LT]") -> bool:
return self.reverse ^ (self.head_key < other.head_key)

def __eq__(self, other: "_KeyIter[LT]") -> bool: # type: ignore[override]
return not (self.head_key < other.head_key or other.head_key < self.head_key)


@overload
def merge(
Expand Down

0 comments on commit c6742d7

Please sign in to comment.