diff options
author | Jörn Hees <joernhees@users.noreply.github.com> | 2015-07-28 10:11:36 +0200 |
---|---|---|
committer | Jörn Hees <joernhees@users.noreply.github.com> | 2015-07-28 10:11:36 +0200 |
commit | 53b56b9b049d0649b6946f7de4642355e5e63949 (patch) | |
tree | 54051da69b9eb3163f3c5cd5657242a3095532d0 | |
parent | dd3c44ce19b8c9a6f66b16dce5651b5cb49c85be (diff) | |
parent | ec93eeddb10b960a943db4a7f2ab664a8f88e049 (diff) | |
download | rdflib-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.py | 12 |
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): |