[Python-ideas] set.add() return value

George Sakkis george.sakkis at gmail.com
Tue Feb 17 17:28:47 CET 2009

On Tue, Feb 17, 2009 at 10:39 AM, Terry Reedy <tjreedy at udel.edu> wrote:

> Returning True or False depending on whether a mutation was done seems like an innovation.

Not really, all Java containers and STL sets and maps do it.

> It is an intriguing idea, but
> doing so just occasionally would add mental burden.  Why now change
> list.extend()? (False if the extension is empty.) or list.sort() (False if
> the list is already sorted.)  List.append(), of course, would always return
> True.

The mental burden is not bigger than, say, learning that you append()
to a list but you add() to a set. Consistency for consistency's sake
is IMHO misguided here; there's only so much you can do by treating
all containers uniformly. Unlike sequences, the motivation for sets
(and dicts for that matter) comes from real use cases so we shouldn't
dismiss this request by an all-or-nothing argument.


More information about the Python-ideas mailing list