summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörn Hees <joernhees@users.noreply.github.com>2015-07-28 10:11:36 +0200
committerJörn Hees <joernhees@users.noreply.github.com>2015-07-28 10:11:36 +0200
commit53b56b9b049d0649b6946f7de4642355e5e63949 (patch)
tree54051da69b9eb3163f3c5cd5657242a3095532d0
parentdd3c44ce19b8c9a6f66b16dce5651b5cb49c85be (diff)
parentec93eeddb10b960a943db4a7f2ab664a8f88e049 (diff)
downloadrdflib-53b56b9b049d0649b6946f7de4642355e5e63949.tar.gz
Merge pull request #501 from joernhees/fix_hash
make Identifier.__hash__ consistent with str.__hash__ stability over runs, fixes #500
-rw-r--r--rdflib/term.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/rdflib/term.py b/rdflib/term.py
index 91cc06ea..561c3e60 100644
--- a/rdflib/term.py
+++ b/rdflib/term.py
@@ -183,7 +183,9 @@ class Identifier(Node, unicode): # allow Identifiers to be Nodes in the Graph
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 @@ class Literal(Identifier):
-- 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):