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
…ythonGH-94775)

(cherry picked from commit 0c66074)

Co-authored-by: Christian Heimes <[email protected]>
  • Loading branch information
miss-islington and tiran authored Jul 12, 2022
1 parent a4b98a7 commit cdd0cab
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 @@ -369,7 +369,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 cdd0cab

Please sign in to comment.