From 25aaeec39eb053a46ab01cf025a4e74d4368eb96 Mon Sep 17 00:00:00 2001 From: beam Date: Thu, 22 Oct 2026 00:29:17 +0000 Subject: [PATCH] beam: make toposort _key robust to unorderable node types --- wizard-work/beam/toposort/toposort.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wizard-work/beam/toposort/toposort.py b/wizard-work/beam/toposort/toposort.py index 0faaf31..22ab30a 100644 --- a/wizard-work/beam/toposort/toposort.py +++ b/wizard-work/beam/toposort/toposort.py @@ -170,7 +170,12 @@ def topo_sort(graph: Mapping[Any, Iterable[Any]]) -> TopoResult: def _key(x): + tn = type(x).__name__ + # Probe whether instances of this type support ordering; if not, fall back + # to a repr/id-based key so mixed or unorderable node types never crash + # the ready-queue sort or cycle reconstruction. try: - return (0, type(x).__name__, x) - except TypeError: - return (1, id(x)) \ No newline at end of file + _ = x < x + except (TypeError, Exception): + return (1, tn, repr(x), id(x)) + return (0, tn, x) \ No newline at end of file