[Python-ideas] [RFC] draft PEP: Dedicated infix operators for matrix multiplication and matrix power

Devin Jeanpierre jeanpierreda at gmail.com
Mon Mar 24 02:47:40 CET 2014


On Sun, Mar 23, 2014 at 6:08 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> -1
>
> The dunder methods are typically named for the most common or
> typical use-case, not generalised or marginal ones e.g.:
>
> +  __add__ not __concat__
> *  __mul__  not __repeat__ or __repetition__
> <  __lt__ not __subset__
> &  __and__ not __ampersand__ or __conjunction__

Thanks for taking issue with the not-silly point.

Ironically enough, all of those but "and" are actually general names
for operators, but I agree that probably wasn't intentional. Anyway,
in practice people seem to get what it means for something to be
"and"ed with another thing. There's an intuition that many things
using the operator treat it in a roughly analogous way, and the same
is true for many other overloadable operators in Python. These
conventions help make code more understandable and are great.

I'm not sure such a thing would happen with an operator for which the
stdlib and documentation and everything insists is only for matrix
multiplication. It'd be like if we had
"__twos_complement_bitwise_and__". It's one thing to generalize an
operator name, and another to not make it very specific.

-- Devin


More information about the Python-ideas mailing list