Skip to content

[networkx] Accept any node/edge data types in graph parameters outside algorithms - #16387

Open
ekanshul wants to merge 4 commits into
python:mainfrom
ekanshul:networkx-graph-data-params
Open

ekanshul wants to merge 4 commits into
python:mainfrom
ekanshul:networkx-graph-data-params

Conversation

@ekanshul

@ekanshul ekanshul commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Part of #16365, following up on #16371.

Preserve NetworkX node and edge data type parameters in graph inputs outside networkx.algorithms, including view return types for edge_subgraph and restricted_view. Functions that create new graphs retain their upstream return types.

The selfloop_edges overloads that also use _U retain Any data parameters to avoid TypeVar default-ordering errors. Merged current main while preserving its FloatInt annotations, scalar attribute overloads, and concrete graph return types.

Agent assistance: Claude Code for the original change; Codex for the merge, review updates, and validation.

…e `algorithms`

Graph parameters annotated as `Graph[_Node]` only accept the default
`dict[str, Any]` node and edge data, so graphs with other `Mapping` data
types are rejected by functions that never look at the data. Type them as
`Graph[_Node, _NodeData, _EdgeData]` in `classes.function`, `convert`,
`convert_matrix`, `generators`, `linalg`, `readwrite` and `utils`, as
already done for `classes` and `drawing`. Return types of graph-building
functions are unchanged; `edge_subgraph()` and `restricted_view()` now
return the input graph's type.

Part of python#16365.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

The other networkx test cases carry the -py312 suffix because numpy's
stubs no longer type-check under --python-version 3.10/3.11, and the
strict test-case pyright config reports partially unknown types for
functions whose return is unannotated or typed with scipy.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

This branch has not been deployed

No deployments
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.

1 participant