]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-94773: deepfreeze: support frozensets with unsortable types (GH-94775)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 12 Jul 2022 16:35:43 +0000 (09:35 -0700)
committerGitHub <noreply@github.com>
Tue, 12 Jul 2022 16:35:43 +0000 (09:35 -0700)
(cherry picked from commit 0c66074e9f8c9728e1d920910d35da0c62f30403)

Co-authored-by: Christian Heimes <christian@python.org>
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 5a64c1ec2e61f7b219e6a84ce19cf2b2e95633b8..c300c3019eefdb98ab9241ed46736afdaae2fb8d 100644 (file)
@@ -369,7 +369,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