Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: use ruff format instead of black #7160

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@
# pre-commit install

repos:
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.3
rev: v3.1.0
hooks:
- id: prettier
files: \.(html|md|toml|yml|yaml)
args: [--prose-wrap=preserve]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.1.8
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
- repo: local
hooks:
- id: generate_requirements.py
Expand Down
4 changes: 2 additions & 2 deletions networkx/algorithms/assortativity/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def degree_assortativity_coefficient(G, x="out", y="in", weight=None, nodes=None
else:
degrees = {d for _, d in G.degree(nodes, weight=weight)}

mapping = {d: i for i, d, in enumerate(degrees)}
mapping = {d: i for i, d in enumerate(degrees)}
M = degree_mixing_matrix(G, x=x, y=y, nodes=nodes, weight=weight, mapping=mapping)

return _numeric_ac(M, mapping=mapping)
Expand Down Expand Up @@ -251,7 +251,7 @@ def numeric_assortativity_coefficient(G, attribute, nodes=None):
if nodes is None:
nodes = G.nodes
vals = {G.nodes[n][attribute] for n in nodes}
mapping = {d: i for i, d, in enumerate(vals)}
mapping = {d: i for i, d in enumerate(vals)}
M = attribute_mixing_matrix(G, attribute, nodes, mapping)
return _numeric_ac(M, mapping)

Expand Down
10 changes: 2 additions & 8 deletions networkx/algorithms/isomorphism/ismags.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,7 @@ def _map_nodes(self, sgn, candidates, constraints, mapping=None, to_be_mapped=No

# The next node is the one that is unmapped and has fewest
# candidates
# Pylint disables because it's a one-shot function.
next_sgn = min(
left_to_map, key=lambda n: min(new_candidates[n], key=len)
) # pylint: disable=cell-var-from-loop
next_sgn = min(left_to_map, key=lambda n: min(new_candidates[n], key=len))
yield from self._map_nodes(
next_sgn,
new_candidates,
Expand All @@ -909,10 +906,7 @@ def _largest_common_subgraph(self, candidates, constraints, to_be_mapped=None):
# "part of" the subgraph in to_be_mapped, and we make it a little
# smaller every iteration.

# pylint disable because it's guarded against by default value
current_size = len(
next(iter(to_be_mapped), [])
) # pylint: disable=stop-iteration-return
current_size = len(next(iter(to_be_mapped), []))

found_iso = False
if current_size <= len(self.graph):
Expand Down
15 changes: 9 additions & 6 deletions networkx/algorithms/isomorphism/tests/test_vf2pp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def test_single_node(self):
dict(zip(G2, it.cycle(labels_many))),
"label",
)
l1, l2 = nx.get_node_attributes(G1, "label"), nx.get_node_attributes(
G2, "label"
l1, l2 = (
nx.get_node_attributes(G1, "label"),
nx.get_node_attributes(G2, "label"),
)

gparams = _GraphParameters(
Expand Down Expand Up @@ -118,8 +119,9 @@ def test_matching_order(self):
dict(zip(G2, it.cycle(labels))),
"label",
)
l1, l2 = nx.get_node_attributes(G1, "label"), nx.get_node_attributes(
G2, "label"
l1, l2 = (
nx.get_node_attributes(G1, "label"),
nx.get_node_attributes(G2, "label"),
)
gparams = _GraphParameters(
G1,
Expand Down Expand Up @@ -155,8 +157,9 @@ def test_matching_order_all_branches(self):
G2.nodes[4]["label"] = "red"
G2.nodes[5]["label"] = "blue"

l1, l2 = nx.get_node_attributes(G1, "label"), nx.get_node_attributes(
G2, "label"
l1, l2 = (
nx.get_node_attributes(G1, "label"),
nx.get_node_attributes(G2, "label"),
)
gparams = _GraphParameters(
G1,
Expand Down
5 changes: 3 additions & 2 deletions networkx/algorithms/shortest_paths/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,9 @@ def all_pairs_all_shortest_paths(G, weight=None, method="dijkstra"):
single_source_all_shortest_paths
"""
for n in G:
yield n, dict(
single_source_all_shortest_paths(G, n, weight=weight, method=method)
yield (
n,
dict(single_source_all_shortest_paths(G, n, weight=weight, method=method)),
)


Expand Down
2 changes: 1 addition & 1 deletion networkx/algorithms/tests/test_bridges.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_no_weight(self):
inf = float("inf")
expected = {(3, 4, inf), (4, 3, inf)}
assert next(nx.local_bridges(self.BB)) in expected
expected = {(u, v, 3) for u, v, in self.square.edges}
expected = {(u, v, 3) for u, v in self.square.edges}
assert set(nx.local_bridges(self.square)) == expected
assert list(nx.local_bridges(self.tri)) == []

Expand Down
3 changes: 2 additions & 1 deletion networkx/utils/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ def test_arbitrary_element(iterable_type, expected):


@pytest.mark.parametrize(
"iterator", ((i for i in range(3)), iter([1, 2, 3])) # generator
"iterator",
((i for i in range(3)), iter([1, 2, 3])), # generator
)
def test_arbitrary_element_raises(iterator):
"""Value error is raised when input is an iterator."""
Expand Down