Shawn Brown <[email protected]> added the comment:
Currently, I'm monkey patching _safe_key (adding a try/except) as follows:
>>> import pprint
>>>
>>> class _safe_key(pprint._safe_key):
>>> def __lt__(self, other):
>>> try:
>>> rv = self.obj.__lt__(other.obj)
>>> except TypeError: # Exception instead of TypeError?
>>> rv = NotImplemented
>>>
>>> if rv is NotImplemented:
>>> rv = (str(type(self.obj)), id(self.obj)) < \
>>> (str(type(other.obj)), id(other.obj))
>>> return rv
>>>
>>> pprint._safe_key = _safe_key
>>>
>>> pprint.pprint({(0,): 1, (None,): 2})
{(None,): 2, (0,): 1}
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue14998>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com