Skip to content

Commit 53b56b9

Browse files
committed
Merge pull request #501 from joernhees/fix_hash
make Identifier.__hash__ consistent with str.__hash__ stability over runs, fixes #500
2 parents dd3c44c + ec93eed commit 53b56b9

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rdflib/term.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ def __ge__(self, other):
183183
return self == other
184184

185185
def __hash__(self):
186-
return hash(type(self)) ^ hash(unicode(self))
186+
t = type(self)
187+
fqn = t.__module__ + '.' + t.__name__
188+
return hash(fqn) ^ hash(unicode(self))
187189

188190

189191
class URIRef(Identifier):
@@ -930,8 +932,12 @@ def __hash__(self):
930932
-- 6.5.1 Literal Equality (RDF: Concepts and Abstract Syntax)
931933
932934
"""
933-
934-
return unicode.__hash__(self) ^ hash(self.language.lower() if self.language else None) ^ hash(self.datatype)
935+
res = super(Literal, self).__hash__()
936+
if self.language:
937+
res ^= hash(self.language.lower())
938+
if self.datatype:
939+
res ^= hash(self.datatype)
940+
return res
935941

936942
@py3compat.format_doctest_out
937943
def __eq__(self, other):

0 commit comments

Comments
 (0)