Skip to content

Overload single_source/multi_source dijkstra and bellman_ford on target - #16746

Open
chiliec wants to merge 2 commits into
python:mainfrom
chiliec:overload-single-source-target
Open

chiliec wants to merge 2 commits into
python:mainfrom
chiliec:overload-single-source-target

Conversation

@chiliec

@chiliec chiliec commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

The single_source_dijkstra, multi_source_dijkstra and single_source_bellman_ford stubs returned the union tuple[dict, dict] | tuple[float, list], so callers had to narrow the result by hand even though the return shape is determined by whether target is passed. Each had a # TODO: overload on target note.

This splits each into two @overloads on target (None -> distances/paths dicts, a node -> distance/path), following the existing shortest_path overloads in generic.pyi, and removes the TODO comments.

Fixes #16744

Verified with the repo's own harness: added a test_cases file (check_single_source_target_overloads-py312.py) asserting both return shapes with assert_type — it failed before the change and passes after. pyright --project pyrightconfig.testcases.json on the networkx test_cases, mypy_test.py stubs/networkx, and stubtest (against networkx 3.6.1) all pass.

chiliec and others added 2 commits November 10, 2026 06:19
These three functions return (distance, path) when target is given and
(distances, paths) otherwise, but the stubs returned the union of both so
callers had to narrow manually. Split each into @overload on target,
mirroring the existing shortest_path overloads in generic.pyi, and drop the
stale # TODO: overload on target comments.

Fixes python#16744
@github-actions

github-actions Bot commented Nov 9, 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.

TODOs in for nx.single_source_bellman_ford

1 participant