bisect uses __cmp__()?

Jeff Epler jepler at unpythonic.net
Tue Jul 29 17:59:09 EDT 2003


On Tue, Jul 29, 2003 at 04:05:46PM -0400, Gary Robinson wrote:
> I'm wondering if bisect.insort is guaranteed to use a __cmp__ method, for
> now and for future python versions, if it exists, for the items being
> inserted?

I don't know for certain what (if anything) is guaranteed, but my guess is that
insort is defined to use only the < operator to compare items.  This
means that you can meet the requirements of the bisect module by
defining __cmp__ or by defining __lt__ (or even by defining __gt__!).  See
	http://python.org/dev/doc/devel/ref/customization.html
for how "rich comparison" works to perform comparisons.  __cmp__ is used
"if rich comparison is not defined".  Thus, existing code with __cmp__
still works just fine.

Jeff





More information about the Python-list mailing list