You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"If a class defines mutable objects and implements a cmp() or eq() method, it should not implement hash(), since the dictionary implementation requires that a key's hash value is immutable (if the object's hash value changes, it will be in the wrong hash bucket)."
Currently, a Graph object defines a __cmp__ method, but not a __hash__ method. This seems to be in accordance with the python docs. However, I guess we are inheriting the __hash__ method from SageObject, so we should redefine the __hash__ method?
Here's a patch:
diff -r 36489d2c9a2e sage/graphs/graph.py
--- a/sage/graphs/graph.py Tue Oct 16 09:50:59 2007 -0500
+++ b/sage/graphs/graph.py Wed Oct 17 10:19:53 2007 -0500
@@ -359,6 +359,20 @@ class GenericGraph(SageObject):
return self._nxg.name
else:
return repr(self)
+
+ def __hash__(self):
+ """
+ Since graphs are mutable, they should not be hashable, so we return a type error.
+
+ EXAMPLE:
+ sage: hash(Graph())
+ Traceback (most recent call last):
+ ...
+ TypeError: graphs are mutable, and so therefore are unhashable
+
+ """
+ raise TypeError, "graphs are mutable, and so therefore are unhashable"
+
def _latex_(self):
"""
Defect resolved by attached patch. Ready to include in 2.8.8!
sagetrac-ekirkmanmannequin
changed the title
hash() on Graph objects changes as the object is mutated
[tested by ekirkman] hash() on Graph objects changes as the object is mutated
Oct 18, 2007
sagetrac-mabshoffmannequin
changed the title
[tested by ekirkman] hash() on Graph objects changes as the object is mutated
hash() on Graph objects changes as the object is mutated
Oct 18, 2007
This is bad:
__hash__
on Graph objects should be overridden to raise a TypeError.Component: combinatorics
Issue created by migration from https://trac.sagemath.org/ticket/911
The text was updated successfully, but these errors were encountered: