From c6742d7d392b6f822c6d06b355906c9b666f77ec Mon Sep 17 00:00:00 2001 From: ybungalobill Date: Wed, 4 Oct 2023 08:28:04 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20stable=20sort=20in=20heapq.merge:=20pytho?= =?UTF-8?q?n=20uses=20both=20=5F=5Feq=5F=5F=20and=20=5F=5Flt=5F=5F=20to?= =?UTF-8?q?=E2=80=A6=20(#112)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix stable sort in heapq.merge: python uses both __eq__ and __lt__ to compare tuples. Co-authored-by: Yakov Galka --- asyncstdlib/heapq.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/asyncstdlib/heapq.py b/asyncstdlib/heapq.py index ac2f5e7..a949bb0 100644 --- a/asyncstdlib/heapq.py +++ b/asyncstdlib/heapq.py @@ -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(