Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 0cb642b

Browse files
committed
Trac #14186 coerce_binop errors with keyword arguments
1 parent 3472a85 commit 0cb642b

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/sage/structure/element.pyx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3205,11 +3205,22 @@ cdef class NamedBinopMethod:
32053205
32063206
sage: from sage.structure.element import NamedBinopMethod
32073207
sage: test_func = NamedBinopMethod(lambda x, y, **kwds: (x, y, kwds), '_add_')
3208+
sage: class test_class(Rational):
3209+
....: def __init__(self,value):
3210+
....: self.v = value
3211+
....: @NamedBinopMethod
3212+
....: def test_add(self, other, keyword='z'):
3213+
....: return (self.v, other, keyword)
32083214
32093215
Calls func directly if the two arguments have the same parent::
32103216
32113217
sage: test_func(1, 2)
32123218
(1, 2, {})
3219+
sage: x = test_class(1)
3220+
sage: x.test_add(1/2)
3221+
(1, 1/2, 'z')
3222+
sage: x.test_add(1/2, keyword=3)
3223+
(1, 1/2, 3)
32133224
32143225
Passes through coercion and does a method lookup if the
32153226
left operand is not the same::
@@ -3220,6 +3231,30 @@ cdef class NamedBinopMethod:
32203231
(1, 2, {'algorithm': 'fast'})
32213232
sage: test_func(1, 1/2)
32223233
3/2
3234+
sage: x.test_add(2)
3235+
(1, 2, 'z')
3236+
sage: x.test_add(2, keyword=3)
3237+
(1, 2, 3)
3238+
3239+
A real example::
3240+
3241+
sage: R1=QQ['x,y']
3242+
sage: R2=QQ['x,y,z']
3243+
sage: f=R1(1)
3244+
sage: g=R1(2)
3245+
sage: h=R2(1)
3246+
sage: f.gcd(g)
3247+
1
3248+
sage: f.gcd(g,algorithm='modular')
3249+
1
3250+
sage: f.gcd(h)
3251+
1
3252+
sage: f.gcd(h,algorithm='modular')
3253+
1
3254+
sage: h.gcd(f)
3255+
1
3256+
sage: h.gcd(f,algorithm='modular')
3257+
1
32233258
"""
32243259
if y is None:
32253260
if self._self is None:
@@ -3230,7 +3265,7 @@ cdef class NamedBinopMethod:
32303265
old_x = x
32313266
x,y = coercion_model.canonical_coercion(x, y)
32323267
if old_x is x:
3233-
return self._func(x,y, *kwds)
3268+
return self._func(x,y, **kwds)
32343269
else:
32353270
return getattr(x, self._name)(y, **kwds)
32363271
else:

0 commit comments

Comments
 (0)