Make XModuleDescriptor hashable again (#22501)

This commit is contained in:
Jeremy Bowman
2019-12-11 14:37:07 -05:00
committed by GitHub
parent d0ab1fc423
commit ca1265a679
2 changed files with 20 additions and 12 deletions

View File

@@ -1263,6 +1263,17 @@ class XModuleDescriptor(XModuleDescriptorToXBlockMixin, HTMLSnippet, ResourceTem
all(getattr(self, field.name) == getattr(other, field.name)
for field in self.fields.values()))
def __hash__(self): # pylint: disable=useless-super-delegation
"""
This isn't technically appropriate since descriptors are actually mutable,
but in practice we rarely modify them after creation or instantiate two
equivalent descriptors in the same process. And we perform graph
operations on large collections of XBlocks that have simply unacceptable
performance if we have to rely on lists and equality rather than sets,
dictionaries, and identity-based hash functions.
"""
return super(XModuleDescriptor, self).__hash__()
def __repr__(self):
return (
"{0.__class__.__name__}("