__imul__ broken for 'objects' in 2.2.1

Alexander Schmolck a.schmolck at gmx.net
Mon Jun 10 09:47:06 EDT 2002


Christos Georgiou <DLNXPEGFQVEB at spammotel.com> writes:

> On 07 Jun 2002 18:17:45 +0100, rumours say that Alexander Schmolck
> <a.schmolck at gmx.net> might have written:
> 
> >class Breaky(object):
> >    def __imul__(self, other):
> >        print "imuling"
> >        return self
> >sq = Breaky()
> >sq *=1.
> >
> >gives:
> >
> >Traceback (most recent call last):[...] line 10, in ?
> >    sq *=1.
> >TypeError: can't multiply sequence to non-int
> 
> Just in case: it is indeed your intention to multiply the object with a
> float, right?
> 

Indeed it is and this nice little bug basically means that the matrix class
I've been working on for quite some time is now somewhat screwed (I need a
new-style class *and* inplace operations).

> PS It seems that a Breaky instance is not (incorrectly) considered a
> sequence in 2.3a0 (20020603).

Nice to hear, but only a limited consolation since it quite some time will
pass before 2.3 comes out and is sufficiently widely adopted.

I really wonder where this bizzarre behavior comes from -- it is really none
of the interpreter's business to take guesses whether my class is a sequence
or not -- finding out if there is a problem with the supplied arguments should
be left to the discretion of the method itself.

alex



More information about the Python-list mailing list