Why in comparing python tuples of objects is __eq__ and then __cmp__ called?
<p>When comparing tuples of objects apparently the <code>__eq__</code> method of the object is called and then the compare method:</p>

<pre><code>import timeit

setup = """
import random
import string
import operator

random.seed('slartibartfast')
d={}

class A(object):
    eq_calls = 0
    cmp_calls = 0
    def __init__(self):
        self.s = ''.join(random.choice(string.ascii_uppercase) for _ in
              range(16))
    def __hash__(self): return hash(self.s)
    def __eq__(self, other):
        self.__class__.eq_calls += 1
        return self.s == other.s
    def __ne__(self, other): return self.s != other.s
    def __cmp__(self, other):
        self.__class__.cmp_calls += 1
        return cmp(self.s ,other.s)

for i in range(1000): d[A()] = 0"""
print min(timeit.Timer("""
for k,v in sorted(d.iteritems()): pass
print A.eq_calls
print A.cmp_calls""", setup=setup).repeat(1, 1))

print min(timeit.Timer("""
for k,v in sorted(d.iteritems(),key=operator.itemgetter(0)): pass
print A.eq_calls
print A.cmp_calls""", setup=setup).repeat(1, 1))
</code></pre>

<p>Prints:</p>

<pre><code>8605
8605
0.0172435735131
0
8605
0.0103719966418
</code></pre>

<p>So in the second case where we compare the keys (that is the A instances) directly <code>__eq__</code> is not called, while in the first case apparently the first ellement of the tuple are compared via equal and then via cmp. But why are they not compared directly via cmp ? What I really don't quite get is the default <code>sorted</code> behavior on the absence of a cmp or key parameter.</p>