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

Chris Angelico rosuav at gmail.com
Sun Jun 17 16:18:49 EDT 2018

On Mon, Jun 18, 2018 at 3:01 AM, Mikhail V <mikhailwas at gmail.com> wrote:
> The idea is to introduce new syntax for the list.append() method.
> Syntax:
> Variant 1.
> Use special case of index, namely omitted index:
>     mylist[] = item

Creation of syntax cannot be done for just one type. So what would
this mean (a) for other core data types, and (b) in the protocols?
What dunder will be called, and with what arguments? For example:

class Foo:
    def __setitem__(self, key, val):
        print("Setting", key, "to", val)

x = Foo()
x[] = 1

What should be printed? Will it come through __setitem__ or are you
requiring a completely different dunder method?

Regardless, I am still a strong -1 on introducing another way to spell


More information about the Python-ideas mailing list