Skip to content

Commit

Permalink
♻️ Refactored by Sourcery
Browse files Browse the repository at this point in the history
  • Loading branch information
Sourcery AI authored and s-weigand committed Oct 3, 2022
1 parent 5c4a80a commit 02f732a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions glotaran/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,7 @@ def iterate_all_items(self) -> Generator[Item, None, None]:
The individual item.
"""
for _, items in self.iterate_items():
iter = items.values() if isinstance(items, dict) else items
yield from iter
yield from items.values() if isinstance(items, dict) else items

def get_parameter_labels(self) -> set[str]:
"""Get all parameter labels.
Expand Down
31 changes: 15 additions & 16 deletions glotaran/parameter/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,23 +204,22 @@ def to_parameter_dict_or_list(self) -> dict | list:
dict | list
A dict or list of parameter definitions.
"""
if any("." in p.label for p in self.all()):
parameter_dict: dict[str, Any] = {}
for parameter in self.all():
path = parameter.label.split(".")
nodes = path[:-2]
node = parameter_dict
for n in nodes:
if n not in node:
node[n] = {}
node = node[n]
upper_node = path[-2]
if upper_node not in node:
node[upper_node] = []
node[upper_node].append(parameter)
return parameter_dict
else:
if all("." not in p.label for p in self.all()):
return list(self.all())
parameter_dict: dict[str, Any] = {}
for parameter in self.all():
path = parameter.label.split(".")
nodes = path[:-2]
node = parameter_dict
for n in nodes:
if n not in node:
node[n] = {}
node = node[n]
upper_node = path[-2]
if upper_node not in node:
node[upper_node] = []
node[upper_node].append(parameter)
return parameter_dict

def set_from_history(self, history: ParameterHistory, index: int):
"""Update the :class:`Parameters` with values from a parameter history.
Expand Down

0 comments on commit 02f732a

Please sign in to comment.