Skip to content

[networkx] Accept any node type in graph functions that took Graph[Hashable] - #16557

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
cristianchiriac:networkx-graph-node-typevar
Oct 20, 2026
Merged

JelleZijlstra merged 1 commit into
python:mainfrom
cristianchiriac:networkx-graph-node-typevar

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

Fixes #16543.

Graph is invariant in its node type, so the functions in networkx/classes/function.pyi that took Graph[Hashable] (set_node_attributes(..., name=...), set_edge_attributes(..., name=None), is_directed, is_empty, number_of_selfloops) rejected a Graph[str]; they now use _Node like the rest of the module.

Upstream: networkx/classes/function.py

Agent: Claude Code

…shable]

Graph is invariant in its node type, so Graph[Hashable] rejected
Graph[str] and similar graphs. Use the _Node type variable, like the
other functions in the module.
@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

scipy-stubs (https://github.com/scipy/scipy-stubs)
+ tests/misc/test_submodules_empty.pyi:3: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

@JelleZijlstra
JelleZijlstra merged commit caeb62f into python:main Oct 20, 2026
74 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect variance for nx.set_node_attributes

2 participants