Skip to content

Commit

Permalink
pythongh-94773: deepfreeze: support frozensets with unsortable types (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiran committed Jul 12, 2022
1 parent ec5db53 commit 0c66074
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
``deepfreeze.py`` now supports code object with frozensets that contain
incompatible, unsortable types.
7 changes: 6 additions & 1 deletion Tools/scripts/deepfreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,12 @@ def generate_complex(self, name: str, z: complex) -> str:
return f"&{name}.ob_base"

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

Expand Down

0 comments on commit 0c66074

Please sign in to comment.