From f886d2849e664c9e742dc84fa4656e2d46e1d72e Mon Sep 17 00:00:00 2001 From: Adam Nelson Date: Wed, 17 Aug 2016 05:07:29 -0400 Subject: [PATCH] Added in a mixin module with an Equality class for mixin use --- openmc/mixin.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 openmc/mixin.py diff --git a/openmc/mixin.py b/openmc/mixin.py new file mode 100644 index 000000000..f4d5f4c8d --- /dev/null +++ b/openmc/mixin.py @@ -0,0 +1,24 @@ +import numpy as np + + +class Equality(object): + """A Class which provides generic __eq__ and __ne__ functionality which + can easily be inherited by downstream classes. + """ + + def __eq__(self, other): + eqval = True + if isinstance(other, type(self)): + for key, value in self.__dict__.items(): + if key in other.__dict__: + if not np.array_equal(value, other.__dict__.get(key)): + eqval = False + else: + eqval = False + else: + eqval = False + + return eqval + + def __ne__(self, other): + return not self.__eq__(other)