This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: __mul__ taken as __rmul__ for mul-by-int only
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: aleax, georg.brandl, georg.brandl
Priority: normal Keywords:

Created on 2003-10-25 21:57 by aleax, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg18758 - (view) Author: Alex Martelli (aleax) * (Python committer) Date: 2003-10-25 21:57
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.
msg18759 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-01-10 22:20
Logged In: YES 
user_id=1188172

This appears to be fixed in 2.5 HEAD, but not in the 2.4 branch.
msg18760 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-02-20 21:50
Logged In: YES 
user_id=849994

It's now fixed in the branch too, thanks to a patch by Armin
I guess.
History
Date User Action Args
2022-04-11 14:56:00adminsetgithub: 39458
2003-10-25 21:57:11aleaxcreate