From dbc9ac4e840e9d47edc0a6a57e18a5420c0de540 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Fri, 19 Jul 2024 13:42:48 -0500 Subject: [PATCH] Fix HeapEntry typing (flagged by mypy 1.11) --- pytools/graph.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pytools/graph.py b/pytools/graph.py index c4c1795..f500805 100644 --- a/pytools/graph.py +++ b/pytools/graph.py @@ -64,11 +64,13 @@ Type Variables Used is included as a key in the graph. """ +from dataclasses import dataclass from typing import ( Any, Callable, Collection, Dict, + Generic, Hashable, Iterator, List, @@ -254,7 +256,8 @@ class CycleError(Exception): self.node = node -class HeapEntry: +@dataclass(frozen=True) +class HeapEntry(Generic[NodeT]): """ Helper class to compare associated keys while comparing the elements in heap operations. @@ -262,9 +265,8 @@ class HeapEntry: Only needs to define :func:`pytools.graph.__lt__` according to <https://github.com/python/cpython/blob/8d21aa21f2cbc6d50aab3f420bb23be1d081dac4/Lib/heapq.py#L135-L138>. """ - def __init__(self, node: NodeT, key: Any) -> None: - self.node = node - self.key = key + node: NodeT + key: Any def __lt__(self, other: HeapEntry) -> bool: return self.key < other.key -- GitLab