[Python-ideas] set.add() return value
Terry Reedy
tjreedy at udel.edu
Tue Feb 17 16:39:37 CET 2009
Steven D'Aprano wrote:
> I'm with Raymond on this.
Me too. Some languages return self from mutating methods (allowing
chaining). Python's builtins and stdlib consistently (afaik) returns
None (preventing chaining). Returning True or False depending on
whether a mutation was done seems like an innovation. 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.
Of course, in Python, having *any* consistent return other than None is
difficult because much mutation is done thru special methods wrapped in
syntax.
tjr
More information about the Python-ideas
mailing list