On Mon, Jun 18, 2018 at 10:07:07AM +1000, Chris Angelico wrote:
> On Mon, Jun 18, 2018 at 9:36 AM, Clint Hepner <[email protected]> wrote:
[...]
> > That’s false. @ was added solely for matrix multiplication.
>
> Ah, confusing bit of language there.
It certainly is. You are talking about *types* and Clint is talking
about *semantics*. As you point out below, you are correct: the @
operator works for any type which defines the correct dunder method:
> >>> class Foo:
> ... def __matmul__(self, other):
> ... print("Me @", other)
> ...
> >>> Foo() @ 5
> Me @ 5
Clint's point that the *motivation* was a single use-case, matrix
multiplication in numpy, is a separate issue.
Mikhail's motivation might solely be appending to lists, but we would
expect this to be a protocol with a dunder method that any type could
opt into.
[...]
> (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.
That's not quite correct: although it isn't strictly speaking an
operator, extended slice notation x[a:b:c] was invented for numpy, and
for a while (Python 1.4 I think?) no core type supported it.
Similarly for using Ellipsis ... in slices. As far as I know, there is
still no core type which supports that.
--
Steve
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/