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

Chris Angelico rosuav at gmail.com
Sun Jun 17 20:07:07 EDT 2018


On Mon, Jun 18, 2018 at 9:36 AM, Clint Hepner <clint.hepner at gmail.com> wrote:
>
>
>> On Jun 17, 2018, at 4:18 PM, Chris Angelico <rosuav at gmail.com> wrote:
>>
>>> 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.
>
> That’s false. @ was added solely for matrix multiplication.

Ah, confusing bit of language there. The @ operator was created for
the benefit of a small number of types (not just one, I think), but it
MUST be available to all types, including custom classes.

>>> class Foo:
...     def __matmul__(self, other):
...         print("Me @", other)
...
>>> Foo() @ 5
Me @ 5

And that's what I was talking about. If "lst[] = X" is to be
syntactically valid, there needs to be a protocol that implements it
(as with "__matmul__" for @).

(It's also worth noting that the @ operator is unique in being created
solely for the benefit of third-party types. Every other operator is
supported by the core types - usually by many of them. Support for a
new operator (or a new form of assignment) would be far greater if
multiple use-cases can be shown. So even interpreted the way I hadn't
intended, my statement isn't completely out of left field; it just
weakens from "cannot" to "is not generally". But syntactically,
"cannot" is still true.)

> -1 as well. Has any one but the proposer shown any support for it yet?

Not to my knowledge. However, this would be far from the first time
that a much-hated-on proposal leads to one that has actual support,
perhaps by restricting it, or maybe by generalizing it, or something.

ChrisA


More information about the Python-ideas mailing list