beam: make toposort _key robust to unorderable node types

This commit is contained in:
beam committed 2026-10-22 00:29:17 +00:00
1 parent 25f6732b2f
commit 25aaeec39e
1 file changed
+8 -3
+8 -3
View File
@@ -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))
_ = x < x
except (TypeError, Exception):
return (1, tn, repr(x), id(x))
return (0, tn, x)