Skip to content
10 changes: 9 additions & 1 deletion mypyc/codegen/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ def _encode_collection_values(
for i in range(count):
value = value_by_index[i]
result.append(str(len(value)))
for item in value:
if isinstance(value, frozenset):
# even though frozensets are not sorted in python, we need to sort the items here
# to improve the determinism of the generated C file, making it easier to compare
# differences in the C files generated by different versions of your code.
sort_helper = {str(v) + type(v).__name__: v for v in value}
items = tuple(sort_helper[key] for key in sorted(sort_helper))
else:
items = value
for item in items:
assert _is_literal_value(item)
index = self.literal_index(item)
result.append(str(index))
Expand Down