On Friday, October 24, 2014 9:45:46 AM UTC-7, Nils Bruin wrote:
> There may be a good reason why Sage chooses to call __radd__ manually
> rather than let python do the work by returning NotImplemented, but if
> there's not perhaps it would be better to stay closer to python's standard?
>
The relevant code is in sage/structure/coerce.pyx:
if not isinstance(y, Element):
op_name = op.__name__
if op_name[0] == 'i':
op_name = op_name[1:]
mul_method = getattr3(y, '__r%s__'%op_name, None)
if mul_method is not None:
res = mul_method(x)
if res is not None and res is not NotImplemented:
return res
# We should really include the underlying error.
# This causes so much headache.
raise TypeError, arith_error_message(x,y,op)
Some superficial experimentation suggests that perhaps just
if not isinstance(y, Element):
return NotImplemented
might do. I'm not sure in what edge cases this interferes with the special
processing of "op_name[0] == 'i':" though.
History is here: http://trac.sagemath.org/ticket/3774 and
http://trac.sagemath.org/ticket/5596 . No comments on why we're not just
returning NotImplemented to be consistent with python's protocol. Robert?
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.