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

Improve handling of graph size in topological sort #10864

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/10851.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve handling of graph size in topological sort, preventing an ``AssertionError`` from being raised.
12 changes: 7 additions & 5 deletions src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,7 @@ def get_installation_order(
return []

graph = self._result.graph
weights = get_topological_weights(
graph,
expected_node_count=len(self._result.mapping) + 1,
)
weights = get_topological_weights(graph, expected_node_count=len(graph))

sorted_items = sorted(
req_set.requirements.items(),
Expand Down Expand Up @@ -273,7 +270,12 @@ def visit(node: Optional[str]) -> None:

# Sanity checks
assert weights[None] == 0
assert len(weights) == expected_node_count

assert len(weights) == expected_node_count, (
len(weights),
expected_node_count,
weights,
)

return weights

Expand Down