Issue 22718: pprint not handline uncomparable dictionary keys, set members well (original) (raw)

import datetime, pprint pprint.pformat({datetime.datetime.now(): 1, None: 1})

Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/pprint.py", line 63, in pformat return PrettyPrinter(indent=indent, width=width, depth=depth).pformat(object) File "/usr/lib/python2.7/pprint.py", line 122, in pformat self._format(object, sio, 0, 0, {}, 0) File "/usr/lib/python2.7/pprint.py", line 140, in _format rep = self._repr(object, context, level - 1) File "/usr/lib/python2.7/pprint.py", line 226, in _repr self._depth, level) File "/usr/lib/python2.7/pprint.py", line 238, in format return _safe_repr(object, context, maxlevels, level) File "/usr/lib/python2.7/pprint.py", line 280, in _safe_repr for k, v in _sorted(object.items()): File "/usr/lib/python2.7/pprint.py", line 82, in _sorted return sorted(iterable) TypeError: can't compare datetime.datetime to NoneType

This is issue is kind of related to http://bugs.python.org/issue14998 but that talks only python 3.2+