A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2014-May/134623.html below:

[Python-Dev] Returning None from methods that mutate object state

[Python-Dev] Returning None from methods that mutate object state [Python-Dev] Returning None from methods that mutate object stateHrvoje Niksic hrvoje.niksic at avl.com
Mon May 19 16:20:01 CEST 2014
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.

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4