From ec93eeddb10b960a943db4a7f2ab664a8f88e049 Mon Sep 17 00:00:00 2001 From: Joern Hees Date: Tue, 21 Jul 2015 16:42:04 +0200 Subject: [PATCH] make Identifier.__hash__ stable wrt. multi processes, fixes #500 --- rdflib/term.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rdflib/term.py b/rdflib/term.py index 91cc06ea0..561c3e607 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -183,7 +183,9 @@ def __ge__(self, other): return self == other def __hash__(self): - return hash(type(self)) ^ hash(unicode(self)) + t = type(self) + fqn = t.__module__ + '.' + t.__name__ + return hash(fqn) ^ hash(unicode(self)) class URIRef(Identifier): @@ -930,8 +932,12 @@ def __hash__(self): -- 6.5.1 Literal Equality (RDF: Concepts and Abstract Syntax) """ - - return unicode.__hash__(self) ^ hash(self.language.lower() if self.language else None) ^ hash(self.datatype) + res = super(Literal, self).__hash__() + if self.language: + res ^= hash(self.language.lower()) + if self.datatype: + res ^= hash(self.datatype) + return res @py3compat.format_doctest_out def __eq__(self, other):