Is __mul__ sufficient for operator '*'?

Mick Krippendorf mad.mick at
Tue Oct 20 05:59:12 CEST 2009

Gabriel Genellina schrieb:
> __special__ methods are searched in the type, not in the instance
> directly. x*y looks for type(x).__mul__ (among other things)

So I thought too, but:

class meta(type):
    def __mul__(*args):
        return 123

class boo(object):
    __metaclass__ = meta

print boo.__mul__

b = boo()
print b * 7

also explodes. Or am I misinterpreting the word "type" here?


More information about the Python-list mailing list