Was: Chain like Ruby

Hi there :wave:

This is a spin-off-topic related to my previous post: Chain like Ruby - #8 by komoto48g

from functools import partial
class apply(partial):
    def __rmatmul__(self, argv):
        return self(argv)
p = apply(print)
>>> p(p)
apply(<built-in function print>)
>>> p@p
TypeError: unsupported operand type(s) for @: 'apply' and 'apply'

I expect both are equivalent, but the latter raises an error. Why doesn’t this code work?
Thanks in advance!

Solved

from functools import partial
class apply(partial):
    def __matmul__(self, argv):
        return self(argv)
    def __rmatmul__(self, argv):
        return self(argv)
p = apply(print)
>>> p@p
apply(<built-in function print>)

Python tries to parse p @ p as p.__matmul__(p) and raises TypeError if it is not found. This issue? seems to occur when the left and the right operand are the same types. I expected python to resolve this as p.__rmatmul__(p) if __matmal__ is not found.