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

Nick Coghlan ncoghlan at gmail.com
Sat May 17 07:14:00 CEST 2014


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 at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list