#12919: Typo in Parent.discover_coerce_map_from
-------------------------------------+--------------------------------------
       Reporter:  nthiery            |         Owner:  robertwb       
           Type:  defect             |        Status:  positive_review
       Priority:  major              |     Milestone:  sage-5.1       
      Component:  coercion           |    Resolution:                 
       Keywords:  days38             |   Work issues:                 
Report Upstream:  N/A                |     Reviewers:  André Apitzsch 
        Authors:  Nicolas M. Thiéry  |     Merged in:                 
   Dependencies:                     |      Stopgaps:                 
-------------------------------------+--------------------------------------

Comment (by mguaypaq):

 Here is a minimal example which illustrates the problem:

 {{{
 sage: class P(Parent):
 ....:     def __init__(self):
 ....:         Parent.__init__(self, category=Sets())
 ....:     Element=ElementWrapper
 ....:
 sage: A = P(); a = A('a')
 sage: B = P(); b = B('b')
 sage: C = P(); c = C('c')
 sage: D = P(); d = D('d')
 sage: Hom(A, B)(lambda x: b).register_as_coercion()
 sage: Hom(B, A)(lambda x: a).register_as_coercion()
 sage: Hom(C, B)(lambda x: b).register_as_coercion()
 sage: Hom(D, C)(lambda x: c).register_as_coercion()
 sage: A(d)
 ---------------------------------------------------------------------------
 UnboundLocalError                         Traceback (most recent call
 last)

 /home/mguaypaq/<ipython console> in <module>()

 /opt/sage-5.0.rc0/local/lib/python2.7/site-
 packages/sage/structure/parent.so in sage.structure.parent.Parent.__call__
 (sage/structure/parent.c:7906)()

 /opt/sage-5.0.rc0/local/lib/python2.7/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.convert_map_from
 (sage/structure/parent.c:15248)()

 /opt/sage-5.0.rc0/local/lib/python2.7/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.discover_convert_map_from
 (sage/structure/parent.c:15399)()

 /opt/sage-5.0.rc0/local/lib/python2.7/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.coerce_map_from
 (sage/structure/parent.c:14021)()

 /opt/sage-5.0.rc0/local/lib/python2.7/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.discover_coerce_map_from
 (sage/structure/parent.c:14958)()

 /opt/sage-5.0.rc0/local/lib/python2.7/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.coerce_map_from
 (sage/structure/parent.c:14021)()

 /opt/sage-5.0.rc0/local/lib/python2.7/site-
 packages/sage/structure/parent.so in
 sage.structure.parent.Parent.discover_coerce_map_from
 (sage/structure/parent.c:14966)()

 UnboundLocalError: local variable 'connecting' referenced before
 assignment
 }}}
 With the patch, the output is now (as it should be):

 {{{
 sage: class P(Parent):
 ....:     def __init__(self):
 ....:         Parent.__init__(self, category=Sets())
 ....:     Element=ElementWrapper
 ....:
 sage: A = P(); a = A('a')
 sage: B = P(); b = B('b')
 sage: C = P(); c = C('c')
 sage: D = P(); d = D('d')
 sage: Hom(A, B)(lambda x: b).register_as_coercion()
 sage: Hom(B, A)(lambda x: a).register_as_coercion()
 sage: Hom(C, B)(lambda x: b).register_as_coercion()
 sage: Hom(D, C)(lambda x: c).register_as_coercion()
 sage: A(d)
 'a'
 }}}
 This could be added as a doctest to detect the problem, but maybe it's not
 necessary for such a clear typo. I would also note that
 [http://trac.sagemath.org/sage_trac/ticket/7420#comment:3 this comment]
 from #7420 points out a cleaner way to fix the problem, but this patch is
 fine too.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12919#comment:9>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to