[ python-Bugs-830261 ] __mul__ taken as __rmul__ for mul-by-int only

SourceForge.net noreply at sourceforge.net
Tue Jan 10 23:20:08 CET 2006


Bugs item #830261, was opened at 2003-10-25 23:57
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=830261&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Alex Martelli (aleax)
Assigned to: Nobody/Anonymous (nobody)
Summary: __mul__ taken as __rmul__ for mul-by-int only

Initial Comment:
Tiniest way to reproduce:
>>> class X(object):
...   def __mul__(self, other): return '%r???' % other
...
>>> x=X()
>>> 23*x
'23???'
>>> 2.3*x
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: can't multiply sequence to non-int
>>>

weird error message hints at cause: Objects/typeobject.c sets sq_repeat slot indifferently for both __mul__ AND __rmul__, then Objects/abstract.c function PyNumber_Multiply checks both operands for sq_repeats, finds it in the RHO and thus calls
sequence_repeat which erroneously succeeds when the LHO
is 23 and fails w/weird error message when it's 2.3.

I'm leaving this unassigned because it's anything but obvious to me what the fix should be!  If anybody HAS obvious fixes to
suggest I'll be glad to implement and commit them, though.

----------------------------------------------------------------------

>Comment By: Georg Brandl (birkenfeld)
Date: 2006-01-10 23:20

Message:
Logged In: YES 
user_id=1188172

This appears to be fixed in 2.5 HEAD, but not in the 2.4 branch.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=830261&group_id=5470


More information about the Python-bugs-list mailing list