sum() requires number, not simply __add__

Ian Kelly ian.g.kelly at
Thu Feb 23 23:00:07 CET 2012

On Thu, Feb 23, 2012 at 2:53 PM, Chris Angelico <rosuav at> wrote:
> On Fri, Feb 24, 2012 at 8:41 AM, Arnaud Delobelle <arnodel at> wrote:
>> _sentinel = object()
>> def sum(iterable, start=_sentinel):
>>    if start is _sentinel:
>> del _sentinel
> Somewhat off-topic: Doesn't the if statement there do a lookup for a
> global, which would mean that 'del _sentinel' will cause it to fail?
> Or have I missed something here?

I believe you're correct.  If you really want to delete the _sentinel
reference though, you could do:

def sum(iterable, start=object()):
    if start is sum.func_defaults[0]:


More information about the Python-list mailing list