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 RealNumber handle ints as
their first input (check the code in Integer.__mod__ for example).  In
Rational.__mod__ on the other hand, the first input is declared as type
Rational to Cython, and thus a TypeError is raised when Python tries to
call __mod__ with inputs (int, Rational).

The solution is to fix the implementation of __mod__ in rational.pyx.
David


On Tue, Jul 9, 2013 at 8:37 AM, Volker Braun <vbraun.n...@gmail.com> wrote:

> 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:
>>
>>
>> sage: int(5) % QQ(2)
>> ------------------------------**------------------------------**
>> ---------------
>> TypeError                                 Traceback (most recent call
>> last)
>> <ipython-input-4-8ec0f9994ded> in <module>()
>> ----> 1 int(Integer(5)) % QQ(Integer(2))
>>
>> TypeError: Argument 'self' has incorrect type (expected sage.rings.
>> rational.Rational, got int)
>>
>>
>>  --
> You received this message because you are subscribed to the Google Groups
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to