Repository navigation
Conversation
…erable `Graph.boruvka_mst` stored `-1` in `cheap_edge` as a "no edge yet" marker next to `[head, tail, weight]` lists. Mixing an int sentinel with list values makes the later unpacking `head, tail, weight = ...` fail type checking (`int & ~Literal[-1]` is not iterable), which was the only `not-iterable` diagnostic left in the repository. Use `None` as the sentinel with an explicit `list[int] | None` value type and narrow through a local variable. Behaviour is unchanged. With that diagnostic gone, remove `rules.not-iterable = "ignore"` from `[tool.ty]` in pyproject.toml. Part of TheAlgorithms#15187
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.
Describe your change
Part of #15187: un-ignores the ty
not-iterablerule.Graph.boruvka_mstingraphs/minimum_spanning_tree_boruvka.pyused-1incheap_edgeto mean "no cheapest edge yet", while the real values are[head, tail, weight]lists. Because an int and a list share the same dict, the laterhead, tail, weight = head_tail_weightproduced the onlynot-iterablediagnostic left in the repo:Changes:
cheap_edgeis nowdict[int, list[int] | None], built withdict.fromkeys(...).Noneis the sentinel and checks useis None/is not None.(set1, set2)that reads the value into a local, so ty can narrow it without anot-subscriptableerror.rules.not-iterable = "ignore"from[tool.ty]inpyproject.toml.Behaviour is unchanged. The existing doctest passes as before. I also compared the MST total weight and edge count against a Kruskal reference on 3,000 random connected graphs, with and without
distinct_weight(), before and after the change, and found no differences.Verification (Python 3.15):
python -m doctest -v graphs/minimum_spanning_tree_boruvka.py: passedruff check/ruff format --checkon the file: cleanty check --exclude-scriptswith the rule enabled: 0not-iterablediagnostics, same total count as onmasterwith the rule ignoredChecklist