Returning None from methods that mutate object state
17 May
2014
17 May
'14
8:14 a.m.
During a conversation today, I realised that the convention of returning None from methods that change an object's state isn't captured the Programming Recommendations section of PEP 8. Specifically, I'm referring to this behaviour:
[].sort() is None True "ABC".lower() is None False
That's a deliberate design choice, and one that has been explained a few times on the list when folks ask why "[].sort().reverse()" doesn't work when "'ABC'.lower().replace('-', '_')" does. Would it be worth adding such a note? Or is it out of scope? Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
3620
Age (days ago)
3624
Last active (days ago)
15 comments
10 participants
participants (10)
-
Antoine Pitrou
-
Chris Barker
-
Greg Ewing
-
Guido van Rossum
-
Hrvoje Niksic
-
Nathaniel Smith
-
Nick Coghlan
-
R. David Murray
-
Steven D'Aprano
-
Terry Reedy