[Python-ideas] Add .= as a method return value assignment operator

David Mertz mertz at gnosis.cx
Thu Sep 27 22:44:45 EDT 2018


This seems like a fairly terrible idea. -100 from me.

Python simply does not tends to chain methods for mutation of objects. A
few libraries—e.g. Pandas—do this, but in those cases actual chaining is
more idiomatic.

This is very different from '+=' or '*=' or even '|=' where you pretty much
expect to wind up with the same type of thing on the binding or mutation.
Of course, you can define operators as you like, so it's not hard and fast,
but it's usual. I.e. '+=' is unlikely to leave the current number domain,
other than according to the regular numeric hierarchy.

text = "foo"
> text .= replace("foo","bar")
>

This one example is okay. But most are awful:

text .= count('foo')
text .= split(';')
text .= find('bar')

In all of those you jump around among various data types bound to 'text'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180927/66f10312/attachment.html>


More information about the Python-ideas mailing list