[Python-ideas] Alternative spelling for list.append()

Michael Selik mike at selik.org
Mon Jun 18 20:56:34 EDT 2018

On Mon, Jun 18, 2018 at 5:52 PM Juancarlo Añez <apalala at gmail.com> wrote:

> The idea is to introduce new syntax for the list.append() method.
>>     mylist[] = item
> For all practical purpose, it would be enough to define that the
> expression:
> mylist += [item]
> gets optimized to mylist.append(item).

Unfortunately, that would create yet another special case of operators
breaking the rules. Most operators invoke magic methods. This would prevent
``+=`` from invoking ``__iadd__`` for lists, since the right-hand side
would need to be compiled differently. It's similar to why ``and`` and
``or`` keywords can't have magic methods.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180618/8a3620d9/attachment.html>

More information about the Python-ideas mailing list