[Python-checkins] gh-94773: deepfreeze: support frozensets with unsortable types (GH-94775)

tiran webhook-mailer at python.org
Tue Jul 12 12:09:57 EDT 2022


https://github.com/python/cpython/commit/0c66074e9f8c9728e1d920910d35da0c62f30403
commit: 0c66074e9f8c9728e1d920910d35da0c62f30403
branch: main
author: Christian Heimes <christian at python.org>
committer: tiran <christian at python.org>
date: 2022-07-12T18:09:47+02:00
summary:

gh-94773: deepfreeze: support frozensets with unsortable types (GH-94775)

files:
A Misc/NEWS.d/next/Build/2022-07-12-13-39-18.gh-issue-94773.koHKm5.rst
M Tools/scripts/deepfreeze.py

diff --git a/Misc/NEWS.d/next/Build/2022-07-12-13-39-18.gh-issue-94773.koHKm5.rst b/Misc/NEWS.d/next/Build/2022-07-12-13-39-18.gh-issue-94773.koHKm5.rst
new file mode 100644
index 0000000000000..ed7e40c91103d
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2022-07-12-13-39-18.gh-issue-94773.koHKm5.rst
@@ -0,0 +1,2 @@
+``deepfreeze.py`` now supports code object with frozensets that contain
+incompatible, unsortable types.
diff --git a/Tools/scripts/deepfreeze.py b/Tools/scripts/deepfreeze.py
index f9fd4e36a81ba..62eeafab0848c 100644
--- a/Tools/scripts/deepfreeze.py
+++ b/Tools/scripts/deepfreeze.py
@@ -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
 



More information about the Python-checkins mailing list