title: Why does list ask about __len__?
body: <pre><code>class Foo:
      def __getitem__(self, item):
          print('getitem', item)
          if item == 6:
              raise IndexError
          return item**2
      def __len__(self):
          print('len')
          return 3
  
  class Bar:
      def __iter__(self):
          print('iter')
          return iter([3, 5, 42, 69])
      def __len__(self):
          print('len')
          return 3
  </code></pre>
  
  <p>Demo:</p>
  
  <pre><code>&gt;&gt;&gt; list(Foo())
  len
  getitem 0
  getitem 1
  getitem 2
  getitem 3
  getitem 4
  getitem 5
  getitem 6
  [0, 1, 4, 9, 16, 25]
  &gt;&gt;&gt; list(Bar())
  iter
  len
  [3, 5, 42, 69]
  </code></pre>
  
  <p>Why does <code>list</code> call <code>__len__</code>?  It doesn't seem to use the result for anything obvious.  A <code>for</code> loop doesn't do it.  This isn't mentioned anywhere in the <a href="https://docs.python.org/3/library/stdtypes.html#iterator-types">iterator protocol</a>, which just talks about <code>__iter__</code> and <code>__next__</code>.  </p>
  
  <p>Is this Python reserving space for the list in advance, or something clever like that?  </p>
  
  <p>(CPython 3.6.0 on Linux)</p>