On Mon, Apr 18, 2011 at 4:13 PM, William Stein <[email protected]> wrote: > Hi, > > I was just explaining to a student in my Sage course how I had > stupidly defined a default __hash__ method for SageObject, which was > -- stupidly -- to just hash the string representation. This was of > course silly and dangerous since only immutable objects should have a > __hash__ method. I then of course pointed out that we must have > fixed this years ago! But.... amazingly we didn't: > > sage: S = SageObject(); S > <type 'sage.structure.sage_object.SageObject'> > sage: hash(S) > -7904861314369208036 > sage: S.__hash__?? > File: /sagenb/flask/sage-4.6.2/devel/sage/sage/structure/sage_object.pyx > Source Code (starting at line 156): > def __hash__(self): > return hash(self.__repr__())
By convention, almost all SageObjects are immutable, so it was probably easier to provide a default and override it for exceptions (matrices and vectors are all that come to mind) than implement it for every concrete subclass. - Robert -- To post to this group, send an email to [email protected] To unsubscribe from this group, send an email to [email protected] For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org
