#15821: Change coercion to not use parent().an_element()
----------------------------+------------------------
       Reporter:  virmaux   |        Owner:  virmaux
           Type:  defect    |       Status:  new
       Priority:  major     |    Milestone:  sage-6.2
      Component:  coercion  |   Resolution:
       Keywords:            |    Merged in:
        Authors:            |    Reviewers:
Report Upstream:  N/A       |  Work issues:
         Branch:            |       Commit:
   Dependencies:            |     Stopgaps:
----------------------------+------------------------

Comment (by SimonKing):

 The error traceback points to this code in
 `sage.structure.parent.Parent._generic_convert_map`:
 {{{
 #!python
    cpdef _generic_convert_map(self, S):
         import coerce_maps
         if self._convert_method_name is not None:
             # handle methods like _integer_
             if PY_TYPE_CHECK(S, type):
                 element_constructor = S
             elif PY_TYPE_CHECK(S, Parent):
                 element_constructor = (<Parent>S)._element_constructor
                 if not PY_TYPE_CHECK(element_constructor, type):
                     # if element_constructor is not an actual class, get
 the element class
                     element_constructor = type(S.an_element())
             else:
                 element_constructor = None
             if element_constructor is not None and
 hasattr(element_constructor, self._convert_method_name):
                 return coerce_maps.NamedConvertMap(S, self,
 self._convert_method_name)
 ...
 }}}
 So, this old code expects that `self._element_constructor` is a type, or
 otherwise it tries to determine the type of an element.

 Today, `_element_constructor_` rather than `_element_constructor` is used,
 but it is not a type (it is a method).

 And looking further down into the code, we find that the element
 constructor actually is not really used: All what we do with it is to ask
 {{{
 hasattr(element_constructor, self._convert_method_name)
 }}}

 The point is: `self._convert_method_name` is None in our case! But if
 there is no `_convert_method_name` then we really don't need the element
 constructor (as a type) in the code.

 Hence, my first guess is that we should first test whether
 `self._convert_method_name` is None, and immediately skip that code block
 if it is.

--
Ticket URL: <http://trac.sagemath.org/ticket/15821#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to