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

(cherry picked from commit 0c66074e9f)

Co-authored-by: Christian Heimes <christian@python.org>
This commit is contained in:
Miss Islington (bot) 2022-07-12 09:35:43 -07:00 committed by GitHub
parent a4b98a792f
commit cdd0cabf92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -0,0 +1,2 @@
``deepfreeze.py`` now supports code object with frozensets that contain
incompatible, unsortable types.

View 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