From 6246083acb1d1fc77f4d9d30ef01bc35791db27f Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner <inform@tiker.net> Date: Mon, 28 Nov 2016 12:26:21 -0600 Subject: [PATCH] Add immutable records --- pytools/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pytools/__init__.py b/pytools/__init__.py index 1dd4d41..9915990 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 + # }}} -- GitLab