[Python-Dev] Returning None from methods that mutate object state
Hrvoje Niksic
hrvoje.niksic at avl.com
Mon May 19 16:20:01 CEST 2014
More information about the Python-Dev mailing list
Mon May 19 16:20:01 CEST 2014
- Previous message: [Python-Dev] Returning None from methods that mutate object state
- Next message: [Python-Dev] Returning None from methods that mutate object state
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 05/17/2014 10:26 AM, Terry Reedy wrote: > When list.pop was added, the convention was changed to > "do not return the 'self' parameter" Do you have a reference for this? It is my understanding that the convention is for mutators to return None, in order to make it clear that the change is destructive. For example, the tutorial at https://docs.python.org/3.4/tutorial/datastructures.html says: """ You might have noticed that methods like insert, remove or sort that modify the list have no return value printed – they return None. [1] This is a design principle for all mutable data structures in Python. """ Methods like list.pop and dict.pop would seem like a case of "practicality beats purity" because it's more convenient (and faster) to delete and retrieve value at the same go.
- Previous message: [Python-Dev] Returning None from methods that mutate object state
- Next message: [Python-Dev] Returning None from methods that mutate object state
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list