From c6cbbce803c98bbbeba8d55086e68f050c3ca575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20N=C3=B6the?= Date: Tue, 5 Mar 2019 20:17:50 +0100 Subject: [PATCH] Set defaults only for fields not passed in __init__ (#1001) --- ctapipe/core/container.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctapipe/core/container.py b/ctapipe/core/container.py index bf5b731ff10..bb38f89e2df 100644 --- a/ctapipe/core/container.py +++ b/ctapipe/core/container.py @@ -122,12 +122,12 @@ class Container(metaclass=ContainerMeta): def __init__(self, **fields): self.meta = {} # __slots__ cannot be provided with defaults - # via class variables, so we use a `__prefix` class variable - # and a `_prefix` in `__slots__` together with a property. + # via class variables, so we use a `container_prefix` class variable + # and an instance variable `prefix` in `__slots__` self.prefix = self.container_prefix - for k, v in self.fields.items(): - setattr(self, k, deepcopy(v.default)) + for k in set(self.fields).difference(fields): + setattr(self, k, deepcopy(self.fields[k].default)) for k, v in fields.items(): setattr(self, k, v)