This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pprint not handline uncomparable dictionary keys, set members well
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: Andreas.Kostyrka, r.david.murray, rhettinger
Priority: normal Keywords:

Created on 2014-10-24 15:47 by Andreas.Kostyrka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg229934 - (view) Author: Andreas Kostyrka (Andreas.Kostyrka) Date: 2014-10-24 15:47
>>> 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+
msg229935 - (view) Author: Andreas Kostyrka (Andreas.Kostyrka) Date: 2014-10-24 15:55
This also applies to sets.
msg229937 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-10-24 16:02
Actually, it applies to datetime, which is is almost unique among python2 datatypes in not being comparable to other types by default.  I'm not sure this is worth fixing in 2.7.
msg230432 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-11-01 08:02
Complex numbers also aren't sortable.

> I'm not sure this is worth fixing in 2.7.

I agree.  That ship sailed a long time ago.
History
Date User Action Args
2022-04-11 14:58:09adminsetgithub: 66907
2014-11-01 08:02:13rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg230432

resolution: wont fix
2014-10-24 16:02:20r.david.murraysetnosy: + r.david.murray
messages: + msg229937
2014-10-24 15:55:12Andreas.Kostyrkasetmessages: + msg229935
title: pprint not handline uncomparable dictionary keys well -> pprint not handline uncomparable dictionary keys, set members well
2014-10-24 15:47:29Andreas.Kostyrkacreate