Skip to content

Commit 0c66074

Browse files
authored
gh-94773: deepfreeze: support frozensets with unsortable types (GH-94775)
1 parent ec5db53 commit 0c66074

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``deepfreeze.py`` now supports code object with frozensets that contain
2+
incompatible, unsortable types.

Tools/scripts/deepfreeze.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,12 @@ def generate_complex(self, name: str, z: complex) -> str:
359359
return f"&{name}.ob_base"
360360

361361
def generate_frozenset(self, name: str, fs: FrozenSet[object]) -> str:
362-
ret = self.generate_tuple(name, tuple(sorted(fs)))
362+
try:
363+
fs = sorted(fs)
364+
except TypeError:
365+
# frozen set with incompatible types, fallback to repr()
366+
fs = sorted(fs, key=repr)
367+
ret = self.generate_tuple(name, tuple(fs))
363368
self.write("// TODO: The above tuple should be a frozenset")
364369
return ret
365370

0 commit comments

Comments
 (0)