Skip to content

Commit

Permalink
Uniformize adding parameter child nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Morendil committed Nov 15, 2018
1 parent e059fec commit 701e9b1
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions openfisca_core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,13 @@ def __init__(self, name = "", directory_path = None, data = None, file_path = No
else:
child_name_expanded = _compose_name(name, child_name)
child = load_parameter_file(child_path, child_name_expanded)
self.children[child_name] = child
setattr(self, child_name, child)
self.add_child(child_name, child)

elif os.path.isdir(child_path):
child_name = os.path.basename(child_path)
child_name_expanded = _compose_name(name, child_name)
child = ParameterNode(child_name_expanded, directory_path = child_path)
self.children[child_name] = child
setattr(self, child_name, child)
self.add_child(child_name, child)

else:
self.file_path = file_path
Expand All @@ -398,8 +396,7 @@ def __init__(self, name = "", directory_path = None, data = None, file_path = No
child_name = str(child_name)
child_name_expanded = _compose_name(name, child_name)
child = _parse_child(child_name_expanded, child, file_path)
self.children[child_name] = child
setattr(self, child_name, child)
self.add_child(child_name, child)

def __call__(self, instant):
return self.get_at_instant(instant)
Expand All @@ -418,7 +415,7 @@ def merge(self, other):
In case of child name conflict, the other node child will replace the current node child.
"""
for child_name, child in other.children.items():
self.children[child_name] = child
self.add_child(child_name, child)

def add_child(self, name, child):
"""
Expand Down

0 comments on commit 701e9b1

Please sign in to comment.