Skip to content

Commit

Permalink
Set defaults only for fields not passed in __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnoe committed Mar 5, 2019
1 parent 423e61e commit fac99cf
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ctapipe/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fac99cf

Please sign in to comment.