[IronPython] Rich comparison usage by IronPython's heapq implementation

Robert Smallshire robert at smallshire.org.uk
Mon Mar 14 06:04:25 PDT 2011


Hello,

I recently ran into some issues with IronPython's heapq implementation
whereby code that functions correctly on CPython failed with IronPython 2.6.
 The issue is that the CPython implementation of heapq only calls __le__()
and __eq__() on the heap elements whereas the IronPython implementation
calls __le__(), __eq__() *and* __gt__().  Although it seems that IronPython
is well within specification to do so, there are some statements in the
Python documentation that only __le__() will be used for sorting.  Of
course, it's arguable whether 'sorting' applies to heapq and indeed other
similar algorithms or containers which rely on a defined ordering.

In any case, this is an avoidable difference between CPython and IronPython
which tripped me up.  I'm not sure whether the correct fix - if one is
needed at all - is to IronPython's heapq implementation, to CPythons
documentation, or to both.

I wrote a little more about the issue here:

  <
http://www.smallshire.org.uk/sufficientlysmall/2011/03/12/specification-of-rich-comparison-protocol-use-by-the-python-standard-library/
>

Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20110314/fa4ee5b1/attachment-0001.htm>


More information about the Users mailing list