Skip to content

Commit 1105aa8

Browse files
new sort key
1 parent a17fe8d commit 1105aa8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

mypyc/codegen/emit.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,3 +1235,11 @@ def c_array_initializer(components: list[str], *, indented: bool = False) -> str
12351235
# Multi-line result
12361236
res.append(indent + ", ".join(current))
12371237
return "{\n " + ",\n ".join(res) + "\n" + indent + "}"
1238+
1239+
1240+
class _mypyc_safe_key(pprint._safe_key):
1241+
"""A custom sort key implementation for pprint that makes the output deterministic
1242+
for all literal types supported by mypyc
1243+
"""
1244+
def __lt__(self, other: "_mypyc_safe_key") -> bool:
1245+
return str(type(self.obj)) + repr(self.obj) < str(type(other.obj)) + repr(other.obj)

0 commit comments

Comments
 (0)