restriction on sum: intentional bug?

Carl Banks pavlovevidence at
Sat Oct 17 23:59:55 CEST 2009

On Oct 17, 2:22 pm, Alan G Isaac < at> wrote:
> On 10/17/2009 7:06 AM, Carl Banks wrote:
> > I'm basically saying here is, by shutting out strings from sum,
> > you don't really lose much in terms of duck typing, because duck
> > typing wouldn't have been that helpful anyway.
> That boils down to an argument for type checking
> whenever you cannot imagine my use case.  I hope
> you do not write your own code that way...

No, it doesn't.  It's an argument that the type check, IN THIS CASE,
doesn't cost you much since duck typing isn't that useful here, IN
THIS CASE, to begin with.  Nothing more.

Extrapolating this argument to be a general defense of type checking
is something you did.

> Here is a use case you might have ruled out with
> that approach.  A PyX `path` defines `__add__`
> so that paths can be combined as subpaths of a
> single path. This is  **VERY USEFUL**.
> Now if I have a list of paths, it is useful to
> to combine them: sum(pathlst,path()).

That's a fair counterargument.  It definitely seems a lot more likely
that some code could be written that works for a list of strings or a
list of path components, meaning that it'd be desirable to have a
single operation which works on both, for which sum() seems like it'd
be a convenient candidate.  Consider my argument weakened somewhat.

Carl Banks

More information about the Python-list mailing list