Repository navigation
Conversation
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
Contributor
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
single_source_dijkstra,multi_source_dijkstraandsingle_source_bellman_fordstubs returned the uniontuple[dict, dict] | tuple[float, list], so callers had to narrow the result by hand even though the return shape is determined by whethertargetis passed. Each had a# TODO: overload on targetnote.This splits each into two
@overloads ontarget(None -> distances/paths dicts, a node -> distance/path), following the existingshortest_pathoverloads ingeneric.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 withassert_type— it failed before the change and passes after.pyright --project pyrightconfig.testcases.jsonon the networkx test_cases,mypy_test.py stubs/networkx, andstubtest(against networkx 3.6.1) all pass.