See https://networkx.org/documentation/stable/reference/generated/networkx.classes.function.set_node_attributes.html
I think nx.set_node_attributes was meant to be typed as taking a nx.Graph of hashable things, but because nx.Graph is invariant in its first type arg this doesn't happen.
Example:
from __future__ import annotations import networkx as nx G: nx.Graph[str] = nx.Graph() G.add_node("hello, world!") nx.set_node_attributes(G, {"hello, world!": 5}, name="example") print(G.nodes["hello, world!"]["example"])
Gets this:
$ uv run mypy x.py x.py:6: error: Argument 1 to "set_node_attributes" has incompatible type "Graph[str, dict[str, Any], dict[str, Any]]"; expected "Graph[Hashable, dict[str, Any], dict[str, Any]]" [arg-type] Found 1 error in 1 file (checked 1 source file) $ uv run x.py 5
Activity