Skip to content

Commit

Permalink
Avoid changing t in randomized_dag_copy() by shallow copying
Browse files Browse the repository at this point in the history
`randomized_dag_copy()` ends up modifying the global variable `t`
when it shuffles the required package list associated to a
`DistPackage`.

This CL fixes this by just shallow copying the list.
  • Loading branch information
kemzeb committed Jul 14, 2023
1 parent f18a321 commit 1f26129
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/test_pipdeptree.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ def randomized_dag_copy(raw: PackageDAG) -> PackageDAG:
randomized_nodes = list(raw._obj.keys()) # noqa: SLF001
random.shuffle(randomized_nodes)
for node in randomized_nodes:
edges = raw._obj[node] # noqa: SLF001
edges = raw._obj[node].copy() # noqa: SLF001
random.shuffle(edges)
randomized_graph[node] = edges
assert set(randomized_graph) == set(raw._obj) # noqa: SLF001
Expand Down

0 comments on commit 1f26129

Please sign in to comment.