summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPradyun Gedam <pradyunsg@users.noreply.github.com>2020-10-27 00:53:41 +0530
committerPradyun Gedam <pradyunsg@users.noreply.github.com>2020-10-27 00:53:41 +0530
commite74116a436f9c50ff513ec8084202d33a8b9e04b (patch)
tree05abaa3fe91bd28bd8ab24c7c1294637b60d910c
parentcffc3a618edb74b5852e628afeb2ee9c097327b1 (diff)
downloadpip-e74116a436f9c50ff513ec8084202d33a8b9e04b.tar.gz
Change assertion in topological sorting
-rw-r--r--src/pip/_internal/resolution/resolvelib/resolver.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/pip/_internal/resolution/resolvelib/resolver.py b/src/pip/_internal/resolution/resolvelib/resolver.py
index cb7d1ae8a..718619b51 100644
--- a/src/pip/_internal/resolution/resolvelib/resolver.py
+++ b/src/pip/_internal/resolution/resolvelib/resolver.py
@@ -180,7 +180,10 @@ class Resolver(BaseResolver):
assert self._result is not None, "must call resolve() first"
graph = self._result.graph
- weights = get_topological_weights(graph)
+ weights = get_topological_weights(
+ graph,
+ expected_node_count=len(self._result.mapping) + 1,
+ )
sorted_items = sorted(
req_set.requirements.items(),
@@ -190,7 +193,7 @@ class Resolver(BaseResolver):
return [ireq for _, ireq in sorted_items]
-def get_topological_weights(graph):
+def get_topological_weights(graph, expected_node_count):
# type: (Graph) -> Dict[Optional[str], int]
"""Assign weights to each node based on how "deep" they are.
@@ -231,7 +234,7 @@ def get_topological_weights(graph):
# Sanity checks
assert weights[None] == 0
- assert len(weights) == len(graph)
+ assert len(weights) == expected_node_count
return weights