Ticket #2283 (closed defect: fixed)
[with patch, positive review] the coercion code (in __mul__) should call __rmul__ when left or right is not coercible to a Sage element
| Reported by: | was | Owned by: | robertwb |
|---|---|---|---|
| Priority: | major | Milestone: | sage-2.10.3 |
| Component: | coercion | Keywords: | |
| Cc: | Work issues: | ||
| Report Upstream: | Reviewers: | ||
| Authors: | Merged in: | ||
| Dependencies: | Stopgaps: |
Description
In this example the last print statement goes boom, but should work fine.
class Foo:
def __rmul__(self, left):
return 'hello'
H = Foo()
print int(3)*H
print 3*H
Attachments
Change History
comment:1 Changed 5 years ago by jason
- Summary changed from the coercion code (in __mul__) should call __rmul__ when left or right is not coercible to a Sage element to [with patch, needs review] the coercion code (in __mul__) should call __rmul__ when left or right is not coercible to a Sage element
comment:2 Changed 5 years ago by jason
Currently, (before this patch), if a class did
_r_action = __rmul__
things would work since the coercion model looks for an _r_action function as a last resort. This patch just makes this line unnecessary by having the coercion system also look for an rmul function (which is standard python; see http://docs.python.org/ref/numeric-types.html)
Apparently this patch is controversial to at least one person, so it probably ought to be discussed.
comment:3 Changed 5 years ago by jason
disclaimer: I don't know much at all about the coercion system; the above statements are from observations made in running examples.
comment:4 Changed 5 years ago by jason
credit goes to gfurnish for noticing and helping track down the segfault that the original patch introduced!
Apply coercion-rmul2.patch instead of coercion-rmul.patch
comment:5 Changed 5 years ago by jason
(and gfurnish also knew how to fix the error causing the segfault!)
comment:7 Changed 5 years ago by was
- Summary changed from [with patch, needs review] the coercion code (in __mul__) should call __rmul__ when left or right is not coercible to a Sage element to [with patch, positive review] the coercion code (in __mul__) should call __rmul__ when left or right is not coercible to a Sage element
Looks good to me. Thanks guys!

