Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make Identifier.__hash__ stable wrt. multi processes, fixes #500 #501

Merged
merged 1 commit into from
Jul 28, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down