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

2014-05-21 Thread Chris Barker
Thanks all, Now I need to try to sum this all up to present to my students. ;-) -Chris On Tue, May 20, 2014 at 4:56 PM, Terry Reedy wrote: > On 5/20/2014 12:30 PM, Chris Barker wrote: > >> [].sort() is None >> > True >> "ABC".lower() is None >> > False >> > >

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

2014-05-20 Thread Guido van Rossum
On Tuesday, May 20, 2014, Greg Ewing wrote: > Chris Barker wrote: > >> Personally, I often miss the ability to chain operations on mutable >> objects, but I can only imagine that that design decision was made for good >> reason. However, as I teach Python, I find I have nothing to say other than

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

2014-05-20 Thread Terry Reedy
On 5/20/2014 12:30 PM, Chris Barker wrote: [].sort() is None > True "ABC".lower() is None > False Is there a reference anywhere as to *why* the convention in Python is to do it that way? In short, reducing bugs induced by mutation of aliased objects. Functional

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

2014-05-20 Thread R. David Murray
On Tue, 20 May 2014 09:30:47 -0700, Chris Barker wrote: > > > > [].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

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

2014-05-20 Thread Greg Ewing
Chris Barker wrote: Personally, I often miss the ability to chain operations on mutable objects, but I can only imagine that that design decision was made for good reason. However, as I teach Python, I find I have nothing to say other than "that's the way it's done in Python". Python has bett

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

2014-05-20 Thread Chris Barker
> > [].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 b

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

2014-05-20 Thread Terry Reedy
On 5/19/2014 10:20 AM, Hrvoje Niksic wrote: 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? I think the fact that Guido accepted, in 2000, my 1999 proposal, with gene

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

2014-05-19 Thread Hrvoje Niksic
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 de

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

2014-05-17 Thread Guido van Rossum
Please preserve the tradition. Adding it to PEP 8 sounds good! ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.co

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

2014-05-17 Thread Nathaniel Smith
On Sat, May 17, 2014 at 6:14 AM, Nick Coghlan wrote: > 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: > >>

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

2014-05-17 Thread Nick Coghlan
On 17 May 2014 19:56, "Antoine Pitrou" wrote: > > On Sat, 17 May 2014 15:14:00 +1000 > Nick Coghlan wrote: > > 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

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

2014-05-17 Thread Steven D'Aprano
On Sat, May 17, 2014 at 04:26:12AM -0400, Terry Reedy wrote: > On 5/17/2014 1:14 AM, Nick Coghlan wrote: > >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.

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

2014-05-17 Thread Antoine Pitrou
On Sat, 17 May 2014 15:14:00 +1000 Nick Coghlan wrote: > 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. This is more an API design guideline than a progra

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

2014-05-17 Thread Nick Coghlan
On 17 May 2014 18:26, Terry Reedy wrote: > On 5/17/2014 1:14 AM, Nick Coghlan wrote: >> >> 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

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

2014-05-17 Thread Terry Reedy
On 5/17/2014 1:14 AM, Nick Coghlan wrote: 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 T

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

2014-05-16 Thread Nick Coghlan
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'