Ticket #10467: 10467-attribute-referee.2.patch

File 10467-attribute-referee.2.patch, 1.4 KB (added by SimonKing, 9 years ago)
  • sage/structure/sage_object.pyx

    # HG changeset patch
    # User Robert Bradshaw <robertwb@math.washington.edu>
    # Date 1292303979 28800
    # Node ID 2b94568ba906ce2ded7e2be336e34b6f0e8f99d0
    # Parent  dbf6106daf3e1143f19dcb5e0ebbf2963fb111d9
    #10467: Referee patch for lookup of private attributes
    [mq]: 10467-attribute-referee.patch
    
    diff -r dbf6106daf3e -r 2b94568ba906 sage/structure/sage_object.pyx
    a b  
    147147        except:
    148148            pass
    149149        try:
    150             return self._repr_()
     150            repr_func = self._repr_
    151151        except AttributeError:
    152152            return str(type(self))
     153        else:
     154            return repr_func()
    153155
    154156    def __hash__(self):
    155157        return hash(self.__repr__())
     
    425427            except (KeyError, ValueError):
    426428                pass
    427429        nm = I.name()
    428         try:
    429             s = self.__getattribute__('_%s_init_'%nm)()
    430         except AttributeError:
     430        init_func = getattr(self, '_%s_init_' % nm, None)
     431        if init_func is not None:
     432            s = init_func()
     433        else:
    431434            try:
    432               s = self._interface_init_(I)
     435                s = self._interface_init_(I)
    433436            except:
    434437                raise NotImplementedError, "coercion of object %s to %s not implemented:\n%s\n%s"%\
    435438                  (repr(self), I)