If the special method returns NotImplemented, then Python will call the
reflected version. So if __mod__(a,b) returns NotImplemented, then Python
will call __rmod__(b,a). I think somewhere the dynamic class stuff strips
out the "r" and forwards it to __mod__(b,a), though that is definitely not
Hi David,
On Wed, Jul 10, 2013 at 08:45:04AM -0600, David Roe wrote:
> If a special method returns NotImplemented, Python will try calling
> the special method on the second input (with the arguments in the
> same order).
That's what I thought too, but I did not manage to find this in the
Note the following:
sage: int(5).__mod__(4)
NotImplemented
sage: int(5).__mod__(QQ(2))
NotImplemented
If a special method returns NotImplemented, Python will try calling the
special method on the second input (with the arguments in the same order).
In this case, the __mod__ methods of Integer and
Look at Integer.__mod__ vs. Rational.__mod__, this'll make it clear how to
fix it.
Apparently the design decision was to call Rational.__mod__(int, Rational)
in that case. It would be nice to have some explanation why.
On Tuesday, July 9, 2013 6:28:20 AM UTC-4, Travis Scrimshaw wrote:
>
>
>