title: Avoiding Python sum default start arg behavior
body: <p>I am working with a Python object that implements <code>__add__</code>, but does not subclass <code>int</code>. <code>MyObj1 + MyObj2</code> works fine, but <code>sum([MyObj1, MyObj2])</code> led to a <code>TypeError</code>, because<code>sum()</code> first attempts <code>0 + MyObj</code>. In order to use <code>sum()</code>, my object needs <code>__radd__</code> to handle <code>MyObj + 0</code> <strong>or</strong> I need to provide an empty object as the <code>start</code> parameter. The object in question is not designed to be empty.</p>
  
  <p>Before anyone asks, the object is not list-like or string-like, so use of join() or itertools would not help. </p>
  
  <p><strong>Edit for details:</strong> the module has a SimpleLocation and a CompoundLocation. I'll abbreviate Location to Loc. A <code>SimpleLoc</code> contains one right-open interval, i.e. [start, end). Adding <code>SimpleLoc</code> yields a <code>CompoundLoc</code>, which contains a list of the intervals, e.g. <code>[[3, 6), [10, 13)]</code>. End uses include iterating through the union, e.g. <code>[3, 4, 5, 10, 11, 12]</code>, checking length, and checking membership.</p>
  
  <p>The numbers can be relatively large (say, smaller than 2^32 but commonly 2^20). The intervals probably won't be extremely long (100-2000, but could be longer). Currently, only the endpoints are stored. I am now tentatively thinking of attempting to subclass <code>set</code> such that the location is constructed as <code>set(xrange(start, end))</code>. However, adding sets will give Python (and mathematicians) fits.</p>
  
  <p>Questions I've looked at:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1218710/pythons-sum-and-non-integer-values">python&#39;s sum() and non-integer values</a></li>
  <li><a href="https://stackoverflow.com/questions/4543129/why-theres-a-start-argument-in-pythons-built-in-sum-function">why there&#39;s a start argument in python&#39;s built-in sum function</a></li>
  <li><a href="https://stackoverflow.com/questions/5082190/help-with-add">TypeError after overriding the __add__ method</a></li>
  </ul>
  
  <p>I'm considering two solutions. One is to avoid <code>sum()</code> and use the loop offered in this <a href="https://stackoverflow.com/questions/11520236/how-to-write-a-python-function-that-adds-all-arguments#comment15226549_11520384">comment</a>. I don't understand why <code>sum()</code> begins by adding the 0th item of the iterable to 0 rather than adding the 0th and 1st items (like the loop in the linked comment); I hope there's an arcane integer optimization reason.</p>
  
  <p>My other solution is as follows; while I don't like the hard-coded zero check, it's the only way I've been able to make <code>sum()</code> work.</p>
  
  <pre><code># ...
  def __radd__(self, other):
      # This allows sum() to work (the default start value is zero)
      if other == 0:
          return self
      return self.__add__(other)
  </code></pre>
  
  <p><strong>In summary,</strong> is there another way to use <code>sum()</code> on objects that can neither be added to integers nor be empty?</p>