Skip to content

Commit 5befc61

Browse files
authored
Consolidate string formatting and conversion (#1402)
1 parent b4bd378 commit 5befc61

File tree

9 files changed

+60
-63
lines changed

9 files changed

+60
-63
lines changed

rustworkx/__init__.py

Lines changed: 50 additions & 53 deletions
Large diffs are not rendered by default.

rustworkx/visualization/matplotlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ def to_marker_edge(marker_size, marker):
731731
mutation_scale=mutation_scale,
732732
color=arrow_color,
733733
linewidth=line_width,
734-
connectionstyle=connectionstyle + f", rad = {rad}",
734+
connectionstyle=f"{connectionstyle}, rad = {rad}",
735735
linestyle=style,
736736
zorder=1,
737737
) # arrows go behind nodes

tests/digraph/test_node_link_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_file_output(self):
126126
self.assertEqual(json_dict, expected)
127127

128128
def test_invalid_path_dir(self):
129-
nonexistent_path = tempfile.gettempdir() + "/" + str(uuid.uuid4()) + "/graph.rustworkx.json"
129+
nonexistent_path = f"{tempfile.gettempdir()}/{uuid.uuid4()}/graph.rustworkx.json"
130130
graph = rustworkx.PyDiGraph()
131131
with self.assertRaises(FileNotFoundError):
132132
rustworkx.node_link_json(graph, path=nonexistent_path)

tests/digraph/test_nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def test_lexicographical_topo_sort(self):
412412
for i in range(5):
413413
dag.add_child(node_a, i, None)
414414
dag.add_parent(3, "A parent", None)
415-
res = rustworkx.lexicographical_topological_sort(dag, lambda x: str(x))
415+
res = rustworkx.lexicographical_topological_sort(dag, str)
416416
# Node values for nodes [6, 0, 5, 4, 3, 2, 1]
417417
expected = ["A parent", "a", 0, 1, 2, 3, 4]
418418
self.assertEqual(expected, res)
@@ -588,7 +588,7 @@ def test_lexicographical_topo_sort_qiskit(self):
588588
cr_1_out = dag.add_node("cr[1]_out")
589589
dag.add_edge(cr_1, cr_1_out, "cr[1]")
590590

591-
res = list(rustworkx.lexicographical_topological_sort(dag, lambda x: str(x)))
591+
res = list(rustworkx.lexicographical_topological_sort(dag, str))
592592
expected = [
593593
"cr[0]",
594594
"cr[0]_out",

tests/digraph/test_substitute_node_with_subgraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_edge_weight_modifier(self):
5555
2,
5656
in_graph,
5757
lambda _, __, ___: 0,
58-
edge_weight_map=lambda edge: edge + "-migrated",
58+
edge_weight_map=lambda edge: f"{edge}-migrated",
5959
)
6060
self.assertEqual([(0, 1), (3, 4), (5, 6), (1, 5), (5, 3)], self.graph.edge_list())
6161
self.assertEqual("edge-migrated", self.graph.get_edge_data(5, 6))

tests/graph/test_node_link_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_file_output(self):
126126
self.assertEqual(json_dict, expected)
127127

128128
def test_invalid_path_dir(self):
129-
nonexistent_path = tempfile.gettempdir() + "/" + str(uuid.uuid4()) + "/graph.rustworkx.json"
129+
nonexistent_path = f"{tempfile.gettempdir()}/{uuid.uuid4()}/graph.rustworkx.json"
130130
graph = rustworkx.PyGraph()
131131
with self.assertRaises(FileNotFoundError):
132132
rustworkx.node_link_json(graph, path=nonexistent_path)

tests/graph/test_substitute_node_with_subgraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_edge_weight_modifier(self):
7474
2,
7575
in_graph,
7676
lambda _, __, ___: 0,
77-
edge_weight_map=lambda edge: edge + "-migrated",
77+
edge_weight_map=lambda edge: f"{edge}-migrated",
7878
)
7979
self.assertEqual([(0, 1), (3, 4), (5, 6), (1, 5), (5, 3)], self.graph.edge_list())
8080
self.assertEqual("edge-migrated", self.graph.get_edge_data(5, 6))

tests/test_graphml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_gzipped(self):
106106
## Test reading a graphmlz
107107
with tempfile.NamedTemporaryFile("w+b") as fd:
108108
fd.flush()
109-
newname = fd.name + ".gz"
109+
newname = f"{fd.name}.gz"
110110
with gzip.open(newname, "wt") as wf:
111111
wf.write(graph_xml)
112112

@@ -130,7 +130,7 @@ def test_gzipped_force(self):
130130
with tempfile.NamedTemporaryFile("w+b") as fd:
131131
# close the file
132132
fd.flush()
133-
newname = fd.name + ".ext"
133+
newname = f"{fd.name}.ext"
134134
with gzip.open(newname, "wt") as wf:
135135
wf.write(graph_xml)
136136

tools/find_stray_release_notes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _main():
4444
failed_files = [x for x in res if x is not None]
4545
if len(failed_files) > 0:
4646
for failed_file in failed_files:
47-
sys.stderr.write("%s is not in the correct location.\n" % failed_file)
47+
sys.stderr.write(f"{failed_file} is not in the correct location.\n")
4848
sys.exit(1)
4949
sys.exit(0)
5050

0 commit comments

Comments
 (0)