Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the coercion code (in __mul__) should call __rmul__ when left or right is not coercible to a Sage element #2283

Closed
williamstein opened this issue Feb 23, 2008 · 8 comments

Comments

@williamstein
Copy link
Contributor

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

Component: coercion

Issue created by migration from https://trac.sagemath.org/ticket/2283

@jasongrout
Copy link
Member

comment:1

Attachment: coercion-rmul.patch.gz

@jasongrout
Copy link
Member

comment:2

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.

@jasongrout
Copy link
Member

comment:3

disclaimer: I don't know much at all about the coercion system; the above statements are from observations made in running examples.

@jasongrout
Copy link
Member

comment:4

Attachment: coercion-rmul2.patch.gz

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

@jasongrout
Copy link
Member

comment:5

(and gfurnish also knew how to fix the error causing the segfault!)

@jasongrout
Copy link
Member

comment:6

The patches above apply to 2.10.2.

@williamstein
Copy link
Contributor Author

comment:7

Looks good to me. Thanks guys!

@sagetrac-mabshoff
Copy link
Mannequin

sagetrac-mabshoff mannequin commented Feb 28, 2008

comment:8

Merged coercion-rmul2.patch in Sage 2.10.3.rc0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants