feature requests

Terry Reedy tjreedy at udel.edu
Sat Oct 5 17:56:03 EDT 2013


On 10/5/2013 11:58 AM, Ethan Furman wrote:
> On 10/05/2013 05:49 AM, macker wrote:
>>>
>>> Ugly, menial lines are a clue that a function to hide it could be
>>> useful.
>>
>> Or a clue to add a trivial change elsewhere (hint for Ethan: `return
>> self` at the end of `Thread.start()`).
>
> I'm aware that would solve your issue.  I'm also aware that Python
> rarely does a 'return self' at the end of methods.

Not returning self is a basic design principle of Python since its 
beginning. (I am not aware of any exceptions and would regard one as 
possibly a mistake.) Guido is aware that not doing so prevents chaining 
of mutation methods. He thinks it very important that people know and 
remember the difference between a method that mutates self and one that 
does not. Otherwise, one could write 'b = a.sort()' and not know 
(remember) that b is just an alias for a. He must have seen this type of 
error, especially in beginner code, in other languages before designing 
Python.

 > Since that probably isn't going to change,

as it would only make things worse.

Note that some mutation methods also return something useful other than 
default None. Examples are mylist.pop() and iterator.__next__ (usually 
accessed by next(iterator)*. So it is impossible for all mutation 
methods to just 'return self'.

* iterator.__next__ is a generalized specialization of list.pop. It can 
only return the 'first' item, but can do so with any iterable, including 
those that are not ordered and those that represent virtual rather than 
concrete collections.

-- 
Terry Jan Reedy




More information about the Python-list mailing list