Skip to content

Commit

Permalink
Convert str.format to f-strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
edparcell committed Aug 23, 2024
1 parent dde717a commit f4faf94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
38 changes: 19 additions & 19 deletions loman/computeengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def add_node(self, name, func=None, **kwargs):
:param executor: Name of executor to run node on
:type executor: string
"""
LOG.debug('Adding node {}'.format(str(name)))
LOG.debug(f'Adding node {name}')
args = kwargs.get('args', None)
kwds = kwargs.get('kwds', None)
has_value = 'value' in kwargs
Expand Down Expand Up @@ -324,10 +324,10 @@ def delete_node(self, name):
:param name: Name of the node to delete. If the node does not exist, a ``NonExistentNodeException`` will be raised.
"""
LOG.debug('Deleting node {}'.format(str(name)))
LOG.debug(f'Deleting node {name}')

if not self.dag.has_node(name):
raise NonExistentNodeException('Node {} does not exist'.format(str(name)))
raise NonExistentNodeException(f'Node {name} does not exist')

if len(self.dag.succ[name]) == 0:
preds = self.dag.predecessors(name)
Expand All @@ -348,17 +348,17 @@ def rename_node(self, old_name, new_name=None):
"""
if hasattr(old_name, '__getitem__') and not isinstance(old_name, str):
for k, v in old_name.items():
LOG.debug('Renaming node {} to {}'.format(str(k), str(v)))
LOG.debug(f'Renaming node {k} to {v}')
if new_name is not None:
raise ValueError("new_name must not be set if rename_node is passed a dictionary")
else:
mapping = old_name
else:
LOG.debug('Renaming node {} to {}'.format(str(old_name), str(new_name)))
LOG.debug(f'Renaming node {old_name} to {new_name}')
if not self.dag.has_node(old_name):
raise NonExistentNodeException('Node {} does not exist'.format(str(old_name)))
raise NonExistentNodeException(f'Node {old_name} does not exist')
if self.dag.has_node(new_name):
raise NodeAlreadyExistsException('Node {} does not exist'.format(str(old_name)))
raise NodeAlreadyExistsException(f'Node {old_name} does not exist')
mapping = {old_name: new_name}

nx.relabel_nodes(self.dag, mapping, copy=False)
Expand Down Expand Up @@ -409,10 +409,10 @@ def insert(self, name, value, force=False):
:param value: The value to be inserted into the node.
:param force: Whether to force recalculation of descendents if node value and state would not be changed
"""
LOG.debug('Inserting value into node {}'.format(str(name)))
LOG.debug(f'Inserting value into node {name}')

if not self.dag.has_node(name):
raise NonExistentNodeException('Node {} does not exist'.format(str(name)))
raise NonExistentNodeException(f'Node {name} does not exist')

if not force:
node_data = self.__getitem__(name)
Expand All @@ -435,11 +435,11 @@ def insert_many(self, name_value_pairs):
:param name_value_pairs: Each tuple should be a pair (name, value), where name is the name of the node to insert the value into.
:type name_value_pairs: List of tuples
"""
LOG.debug('Inserting value into nodes {}'.format(", ".join(str(name) for name, value in name_value_pairs)))
LOG.debug(f'Inserting value into nodes {", ".join(str(name) for name, value in name_value_pairs)}')

for name, value in name_value_pairs:
if not self.dag.has_node(name):
raise NonExistentNodeException('Node {} does not exist'.format(str(name)))
raise NonExistentNodeException(f'Node {name} does not exist')

stale = set()
computable = set()
Expand Down Expand Up @@ -601,11 +601,11 @@ def _get_func_args_kwds(self, name):
elif param.type == _ParameterType.KWD:
kwds[param.name] = param.value
else:
raise Exception("Unexpected param type: {}".format(param.type))
raise Exception(f"Unexpected param type: {param.type}")
return f, executor_name, args, kwds

def _compute_nodes(self, names, raise_exceptions=False):
LOG.debug('Computing nodes {}'.format(list(map(str, names))))
LOG.debug(f'Computing nodes {names}')

futs = {}

Expand Down Expand Up @@ -640,7 +640,7 @@ def run(name):
for n in self.dag.successors(name):
logging.debug(str(name) + ' ' + str(n) + ' ' + str(computed))
if n in computed:
raise LoopDetectedException("Calculating {} for the second time".format(name))
raise LoopDetectedException(f"Calculating {name} for the second time")
self._try_set_computable(n)
node0 = self.dag.nodes[n]
state = node0[NodeAttributes.STATE]
Expand All @@ -664,9 +664,9 @@ def _get_calc_nodes(self, name):
ancestors = nx.ancestors(g, name)
for n in ancestors:
if state == States.UNINITIALIZED and len(self.dag.pred[n]) == 0:
raise Exception("Cannot compute {} because {} uninitialized".format(name, n))
raise Exception(f"Cannot compute {name} because {n} uninitialized")
if state == States.PLACEHOLDER:
raise Exception("Cannot compute {} because {} is placeholder".format(name, n))
raise Exception(f"Cannot compute {name} because {n} is placeholder")

ancestors.add(name)
nodes_sorted = nx.topological_sort(g)
Expand Down Expand Up @@ -1048,7 +1048,7 @@ def get_field_value(tuple):
return getattr(tuple, field)
return get_field_value
for field in namedtuple_type._fields:
node_name = "{}.{}".format(name, field)
node_name = f'{name}.{field}'
self.add_node(node_name, make_f(field), kwds={'tuple': name}, group=group)
self.set_tag(node_name, SystemTags.EXPANSION)

Expand Down Expand Up @@ -1076,7 +1076,7 @@ def f(xs):
is_error = True
results.append(subgraph.copy())
if is_error:
raise MapException("Unable to calculate {}".format(result_node), results)
raise MapException(f"Unable to calculate {result_node}", results)
return results
self.add_node(result_node, f, kwds={'xs': input_node})

Expand Down Expand Up @@ -1127,7 +1127,7 @@ def print_errors(self):
"""
for n in self.nodes():
if self.s[n] == States.ERROR:
print("{}".format(n))
print(f"{n}")
print("=" * len(n))
print()
print(self.v[n].traceback)
Expand Down
4 changes: 2 additions & 2 deletions loman/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def create_viz_dag(comp_dag, colors='state', cmap=None):
max_duration = max(timing.duration for timing in timings.values() if hasattr(timing, 'duration'))
min_duration = min(timing.duration for timing in timings.values() if hasattr(timing, 'duration'))
else:
raise ValueError('{} is not a valid loman colors parameter for visualization'.format(colors))
raise ValueError(f"{colors} is not a valid loman colors parameter for visualization")

viz_dag = nx.DiGraph()
node_index_map = {}
for i, (name, data) in enumerate(comp_dag.nodes(data=True)):
short_name = "n{}".format(i)
short_name = f'n{i}'
attr_dict = {
'label': name,
'style': 'filled',
Expand Down

0 comments on commit f4faf94

Please sign in to comment.