Whole file

gaogaotiantian/objprint

The author described this change as Fix printing unsortable dict (#54). It counts as a record because the check below fails on the code as it stood at 95e6a62fb and passes on b4808f08c, with nothing else changed between the two runs.

Fix saved2022-03-08
Sharing licenceApache-2.0 · LICENSE
Change size+6 1

What the code was meant to do, written into the code itself as a save note

Fix printing unsortable dict (#54)

The change

129129 if isinstance(obj, list) or isinstance(obj, tuple) or isinstance(obj, set):
130130 elems = (f"{self._objstr(val, memo, indent_level + 1, cfg)}" for val in obj)
131131 elif isinstance(obj, dict):
132+ items = obj.items()
133+ try:
134+ items = sorted(items)
135+ except TypeError:
136+ pass
132137 elems = (
133138 f"{self._objstr(key, None, indent_level + 1, cfg)}: {self._objstr(val, memo, indent_level + 1, cfg)}"
134- for key, val in sorted(obj.items())
139+ for key, val in items
135140 )
136141 else:
137142 # It's an object

The check that tells the two apart

failpass·tests/test_objprint.py::TestObjprint::test_unsortable_dict

Check file tests/test_objprint.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it95e6a62fb145513b915061eb56f797982b70730d
Broken version dated2022-03-06
Moduleobjprint.objprint
Units changedObjPrint
Fingerprinta56815b95a6e1a3a
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in gaogaotiantian/objprint