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

Commit

Permalink
trac #17673: __module__/__name__ for coerce_binop
Browse files Browse the repository at this point in the history
  • Loading branch information
videlec committed Jan 25, 2015
1 parent a70d682 commit 7d2009c
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/sage/structure/element.pyx
Expand Up @@ -3304,7 +3304,7 @@ def coercion_traceback(dump=True):
return coercion_model.exception_stack()
cdef class NamedBinopMethod:
cdef class NamedBinopMethod(object):
"""
A decorator to be used on binary operation methods that should operate
on elements of the same parent. If the parents of the arguments differ,
Expand All @@ -3316,17 +3316,27 @@ cdef class NamedBinopMethod:
operations like ``_add_``, ``_sub_``, etc. in that both operands are
guaranteed to have exactly the same parent.
"""
cdef _self
cdef _func
cdef _name
cdef object _self
cdef object _func
cdef str _name
cdef public str __name__
cdef public str __module__
def __init__(self, func, name=None, obj=None):
"""
TESTS::
sage: from sage.structure.element import NamedBinopMethod
sage: NamedBinopMethod(gcd)(12, 15)
sage: f = NamedBinopMethod(gcd)
sage: f(12, 15)
3
Check that module and name are correctly initialized (:trac:`17673`)::
sage: f.__module__
'sage.rings.arith'
sage: f.__name__
'gcd'
"""
self._func = func
if name is None:
Expand All @@ -3336,8 +3346,12 @@ cdef class NamedBinopMethod:
name = func.__func__.__name__
else:
name = func.__name__
self._name = name
self._name = self.__name__ = name
self._self = obj
try:
self.__module__ = func.__module__
except AttributeError:
self.__module__ = func.__objclass__.__module__
def __call__(self, x, y=None, **kwds):
"""
Expand Down

0 comments on commit 7d2009c

Please sign in to comment.