diff --git a/pytools/__init__.py b/pytools/__init__.py index 1dd4d4154b3833e5cc1579916aca2c2cdda609fc..9915990d9abf0ceeb12b15720fcf778c80cf38df 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -197,6 +197,19 @@ class Record(RecordWithoutPickling): def __ne__(self, other): return not self.__eq__(other) + +class ImmutableRecordWithoutPickling(RecordWithoutPickling): + "Hashable record. Does not explicitly enforce immutability." + + def __hash__(self): + return hash( + (type(self),) + tuple(getattr(self, field) + for field in self.__class__.fields)) + + +class ImmutableRecord(Record, ImmutableRecordWithoutPickling): + pass + # }}}