In-place multiply and new style classes

Hi, I'm Todd Miller and I work at the Space Telescope Science Institute on Numarray. Numarray is STSCI's stab at improving Numeric. This is my first post here. Today one of the guys in my branch noticed that Numarray's in-place multiply was raising this bizarre exception: --> a = ones ((5,), Float32) --> a array([1., 1., 1., 1., 1.], type=Float32) --> a *= 62. Traceback (innermost last): File "<console>", line 1, in ? TypeError: can't multiply sequence to non-int I looked into this for a couple hours and discovered the following: class test1(object): """A new-style class""" def __init__(self): pass def __imul__(self, other): print "no luck here!"
t1 = test1() t1 *= 62. Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: can't multiply sequence to non-int
Todd -- Todd Miller jmiller@stsci.edu STSCI / SSG (410) 338 4576

Martin v. Loewis wrote:
Todd Miller <jmiller@stsci.edu> <mailto:jmiller@stsci.edu> writes:
TypeError: can't multiply sequence to non-int
It seems that this has been fixed in the CVS.
Regards, Martin
I updated to the head and I still get:
class test1(object): def __init__(self): pass def __imul__(self, other): print "no luck here!" Python 2.3a0 (#3, Mar 27 2002, 15:27:32) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
t = test1()
t *= 1 no luck here!
t *= 1. Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: unsupported operand type(s) for *=: 'NoneType' and 'float'
The latter is still a problem for me because Numarray needs to implement both sequence and number protocols, and wants the number protocol to dominate *=. What I think I see happening in both cases is the sequence protocol executing. Sorry if this is an old issue... Todd -- Todd Miller jmiller@stsci.edu <mailto:jmiller@stsci.edu> STSCI / SSG (410) 338 4576
participants (2)
-
martin@v.loewis.de
-
Todd Miller