Issue 830261: mul taken as rmul for mul-by-int only (original) (raw)
Tiniest way to reproduce:
class X(object): ... def mul(self, other): return '%r???' % other ... x=X() 23x '23???' 2.3x Traceback (most recent call last): File "", 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.