[Python-ideas] Method chaining notation

Andrew Barnert abarnert at yahoo.com
Mon Feb 24 08:34:23 CET 2014


On Feb 23, 2014, at 23:14, Ron Adam <ron3200 at gmail.com> wrote:

> On 02/23/2014 05:52 PM, Stephen J. Turnbull wrote:
>> Ron Adam writes:
>> 
>>  > The operator you want is one for an in place method call.
>> 
>>  >     seq = [] .= extend(get_data()) .= sort()
>> 
>> That looks like anything but Python to me.
> 
> Is it really all that different from this?
> 
> >>> "Py" . __add__("th") . __add__("on")
> 'Python'

Well, yes, it is. But, more importantly, who cares? That code is horribly unreadable and unpythonic. OK, I don't think PEP8 has a guideline saying "don't call __add__ when you can just use +", but only because it's so obvious it doesn't need to be stated. (And I'm pretty sure it _does_ have a guideline saying not to put spaces around the attribute dot.)

So, is your argument is "my code looks kind of like some horribly unreadable and unpythonic, but legal, code, and therefore it should also be legal despite being unreadable and unpythonic?"


More information about the Python-ideas mailing list