Skip to content

Commit 9a4083c

Browse files
committed
refact(net): f-strings all
1 parent ebc300e commit 9a4083c

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

graphtik/network.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class _DataNode(str):
133133
__slots__ = () # avoid __dict__ on instances
134134

135135
def __repr__(self):
136-
return 'DataNode("%s")' % self
136+
return f"DataNode('{self}')"
137137

138138

139139
class _EvictInstruction(str):
@@ -148,7 +148,7 @@ class _EvictInstruction(str):
148148
__slots__ = () # avoid __dict__ on instances
149149

150150
def __repr__(self):
151-
return 'EvictInstruction("%s")' % self
151+
return f"EvictInstruction('{self}')"
152152

153153

154154
class _PinInstruction(str):
@@ -167,7 +167,7 @@ class _PinInstruction(str):
167167
__slots__ = () # avoid __dict__ on instances
168168

169169
def __repr__(self):
170-
return 'PinInstruction("%s")' % self
170+
return f"PinInstruction('{self})"
171171

172172

173173
# TODO: maybe class Solution(object):
@@ -259,12 +259,10 @@ def _build_pydot(self, **kws):
259259
return build_pydot(**mykws)
260260

261261
def __repr__(self):
262-
steps = ["\n +--%s" % s for s in self.steps]
263-
return "ExecutionPlan(needs=%s, provides=%s, steps:%s)" % (
264-
aslist(self.needs, "needs"),
265-
aslist(self.provides, "provides"),
266-
"".join(steps),
267-
)
262+
needs = aslist(self.needs, "needs")
263+
provides = aslist(self.provides, "provides")
264+
steps = "".join(f"\n +--{s}" for s in self.steps)
265+
return f"ExecutionPlan(needs={needs}, provides={provides}, steps:{steps})"
268266

269267
def validate(self, inputs: Items, outputs: Items):
270268
"""
@@ -448,7 +446,7 @@ def _execute_sequential_method(self, solution, overwrites, executed):
448446
elif isinstance(step, _PinInstruction):
449447
self._pin_data_in_solution(step, solution, pinned_values, overwrites)
450448
else:
451-
raise AssertionError("Unrecognized instruction.%r" % step)
449+
raise AssertionError(f"Unrecognized instruction.{step}")
452450

453451
def execute(self, named_inputs, outputs=None, *, overwrites=None, method=None):
454452
"""
@@ -559,8 +557,8 @@ def __init__(self, *operations, graph=None):
559557
self._cached_plans = {}
560558

561559
def __repr__(self):
562-
steps = ["\n +--%s" % s for s in self.graph.nodes]
563-
return "Network(%s)" % "".join(steps)
560+
steps = [f"\n +--{s}" for s in self.graph.nodes]
561+
return f"Network({''.join(steps)})"
564562

565563
def _build_pydot(self, **kws):
566564
from .plot import build_pydot
@@ -654,7 +652,7 @@ def _unsatisfied_operations(self, dag, inputs: Collection):
654652
for future_op in dag.adj[node]:
655653
op_satisfaction[future_op].add(node)
656654
else:
657-
raise AssertionError("Unrecognized network graph node %r" % node)
655+
raise AssertionError(f"Unrecognized network graph node {node}")
658656

659657
return unsatisfied
660658

@@ -920,7 +918,7 @@ def add_step_once(step):
920918
add_step_once(_EvictInstruction(provide))
921919

922920
else:
923-
raise AssertionError("Unrecognized network graph node %r" % node)
921+
raise AssertionError(f"Unrecognized network graph node {node}")
924922

925923
return steps
926924

0 commit comments

Comments
 (0)