Skip to content
Merged
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
6 changes: 5 additions & 1 deletion mypy/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ def prepare_sccs(
sccs: list[set[T]], edges: dict[T, list[T]]
) -> dict[AbstractSet[T], set[AbstractSet[T]]]:
"""Use original edges to organize SCCs in a graph by dependencies between them."""
sccsmap = {v: frozenset(scc) for scc in sccs for v in scc}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wanted to keep the dict comprehension, you could use an assignment expression

sccsmap = {v: s for scc in sccs if (s := frozenset(scc)) is not None for v in scc}  # type: ignore[redundant-expr]

It adds an additional if not None check for each scc that's always true but necessary to use :=.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, but I think this version is clearer

sccsmap = {}
for scc in sccs:
scc_frozen = frozenset(scc)
for v in scc:
sccsmap[v] = scc_frozen
data: dict[AbstractSet[T], set[AbstractSet[T]]] = {}
for scc in sccs:
deps: set[AbstractSet[T]] = set()
Expand Down
Loading