]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94773: deepfreeze: support frozensets with unsortable types (GH-94775)
authorChristian Heimes <christian@python.org>
Tue, 12 Jul 2022 16:09:47 +0000 (18:09 +0200)
committerGitHub <noreply@github.com>
Tue, 12 Jul 2022 16:09:47 +0000 (18:09 +0200)
Misc/NEWS.d/next/Build/2022-07-12-13-39-18.gh-issue-94773.koHKm5.rst [new file with mode: 0644]
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 (file)
index 0000000..ed7e40c
--- /dev/null
@@ -0,0 +1,2 @@
+``deepfreeze.py`` now supports code object with frozensets that contain
+incompatible, unsortable types.
index f9fd4e36a81baa93200f1e6d6096f0505a82c6ff..62eeafab0848cbcae7e629d24f904843400d2e07 100644 (file)
@@ -359,7 +359,12 @@ class Printer:
         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