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
coerce_binop has dangerous behaviour wrt additional arguments #21322
Comments
Changed author from Johan Rosenkilde to Johan Rosenkilde, Xavier Caruso |
Branch: u/jsrn/21322_coerce_binop |
Commit: |
comment:3
As described. New commits:
|
Changed keywords from none to sd75 |
comment:4
For information, the popular decorator |
comment:5
I got the following, possibly spurious doc-test failures:
|
Changed branch from u/jsrn/21322_coerce_binop to u/caruso/21322_coerce_binop |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:10
I don't get any of the errors pointed by jsm. Otherwise, lgtm. New commits:
|
Reviewer: Miguel Marco |
Changed branch from u/caruso/21322_coerce_binop to |
@coerce_binop
is an important decorator used on binary operators to automagically apply the coercion framework on its arguments. It's widely used on e.g.gcd
operations (_add_
,_sub_
etc. have coercion handled with another mechanism).The current
@coerce_binop
has the following dangerous behaviour, where, if the decorated method is given an extra unnamed argument, theself
-argument is swallowed:The reason is that
@coerce_binop
included a hack to allow calls such asPolynomial.gcd(f,g)
wheref
andg
are polynomials and thegcd
method isdecorated with
@coerce_binop
. The reason that this required a hack at all is that@coerce_binop
was implemented as a class: it seems that creating decorators as classes implies a very unfortunate behaviour:the above prints something like
and then crashes with
This is because the
self
in__call__
ofMyDec
becomes theMyDec
instance-- the
A
instance is never passed to the decorating class instance!The solution here is to rewrite
coerce_binop
as a function. At the same time, we can use@sage_wraps
which ensures proper documentation (e.g. source file and line which was not retained in the previouscoerce_binop
).CC: @xcaruso @miguelmarco
Component: coercion
Keywords: sd75
Author: Johan Rosenkilde, Xavier Caruso
Branch/Commit:
7344f3a
Reviewer: Miguel Marco
Issue created by migration from https://trac.sagemath.org/ticket/21322
The text was updated successfully, but these errors were encountered: