sum() requires number, not simply __add__

Arnaud Delobelle arnodel at
Thu Feb 23 16:59:08 EST 2012

On 23 February 2012 21:53, 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?

Yes, you're right :)  Change the signature to

def sum(iterable, start=_sentinel, _sentinel=_sentinel):

This is not pretty...


More information about the Python-list mailing list