Re: [sage-devel] Re: Taking a python int modulo a rational

2013-07-11 Thread Volker Braun
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

Re: [sage-devel] Re: Taking a python int modulo a rational

2013-07-11 Thread Nicolas M. Thiery
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

Re: [sage-devel] Re: Taking a python int modulo a rational

2013-07-10 Thread David Roe
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

[sage-devel] Re: Taking a python int modulo a rational

2013-07-09 Thread Volker Braun
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: > > >