On 26/06/20 4:01 am, Steele Farnsworth wrote:
My point was only that, as far as I know, all the methods for built in container types that serve only to change what is contained return None, and that this was an intentional design choice, so changing it in one case would have to evoke a larger discussion about what those sorts of methods should return.

The reason for that convention is so that there is no confusion
about which methods return new objects and which modify the object
in place.

However, achieving that goal only requires that mutating methods
don't return 'self'. It doesn't mean they can't return some other
value that might be useful.

A wider argument against that might be that methods should be
classifiable into "procedures" (that have side effects but not
return values) and "functions" (that return values but don't
have side effects). I'm not sure whether that's considered part
of the Python design philosophy -- I don't remember seeing much
discussion about it.

In this particular case, it might be better to add a new method
rather than redefining the existing 'add' method, because if code
assuming the new behaviour were run on an older version of Python,
it would fail in an obscure way.

--
Greg
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ZYYUMHMD2SCNOETAPQQHDCET7JUQ5ZNZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to