From daea046908a85918c94464b81fef1d7d8d1db6a5 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Sun, 21 Jan 2018 14:09:39 +0000 Subject: [PATCH] Fix multiple-inheritance object creation issue. --- fsl/data/mesh.py | 8 ++++++++ fsl/utils/meta.py | 9 +++++++-- fsl/utils/notifier.py | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fsl/data/mesh.py b/fsl/data/mesh.py index dcf4054e4..bb2d9b237 100644 --- a/fsl/data/mesh.py +++ b/fsl/data/mesh.py @@ -144,6 +144,14 @@ class Mesh(notifier.Notifier, meta.Meta): """ + def __new__(cls, *args, **kwargs): + """Create a ``Mesh``. We must override ``__new__``, otherwise the + :class:`Meta` and :class:`Notifier` ``__new__`` methods will not be + called correctly. + """ + return super(Mesh, cls).__new__(cls, *args, **kwargs) + + def __init__(self, indices, name='mesh', diff --git a/fsl/utils/meta.py b/fsl/utils/meta.py index f380fdbf1..3e65d398e 100644 --- a/fsl/utils/meta.py +++ b/fsl/utils/meta.py @@ -27,8 +27,13 @@ class Meta(object): setMeta """ - def __init__(self): - self.__meta = collections.OrderedDict() + def __new__(cls, *args, **kwargs): + """Initialises a ``Meta`` instance. """ + + new = super(Meta, cls).__new__(cls) + new.__meta = collections.OrderedDict() + + return new def metaKeys(self): diff --git a/fsl/utils/notifier.py b/fsl/utils/notifier.py index f207a2be2..cd07204e4 100644 --- a/fsl/utils/notifier.py +++ b/fsl/utils/notifier.py @@ -94,7 +94,7 @@ class Notifier(object): instance. """ - new = object.__new__(cls) + new = super(Notifier, cls).__new__(cls) # Listeners are stored in this # -- GitLab