[New-bugs-announce] [issue22718] pprint not handline uncomparable dictionary keys well

Andreas Kostyrka report at bugs.python.org
Fri Oct 24 17:47:29 CEST 2014

New submission from Andreas Kostyrka:

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

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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+

components: Library (Lib)
messages: 229934
nosy: Andreas.Kostyrka
priority: normal
severity: normal
status: open
title: pprint not handline uncomparable dictionary keys well
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list