Repository navigation
Description
Sub-task of #15187 — good first issue
We're incrementally shrinking the [tool.ty] rule-ignore list so ty can eventually become a required gate (see the tracking issue #15187). As discussed there, the low-hanging rules are best carved into standalone, self-contained tasks. This is the first one.
Rule: invalid-assignment — flags assigning a value whose type doesn't match the declared type of the target (attribute, variable, etc.). In this codebase every occurrence is a small, local fix — almost all are linked-list / tree next/previous attributes declared implicitly as None (or Node | None) and then reassigned a Node. The fix is an explicit annotation, e.g.:
# before: ty infers `next` as `None`, so `self.next = Node(...)` is invalid
self.next = None
# after:
self.next: "Node | None" = NoneCurrent occurrences (23 diagnostics across 9 files)
-
cellular_automata/conways_game_of_life.py— line 86 -
cellular_automata/one_dimensional.py— line 62 -
data_structures/binary_tree/non_recursive_segment_tree.py— line 63 -
data_structures/heap/binomial_heap.py— lines 225, 286 -
data_structures/linked_list/doubly_linked_list.py— lines 96, 103, 106, 145, 149, 155, 156, 175, 176 -
data_structures/linked_list/singly_linked_list.py— lines 158, 221, 322 -
fractals/mandelbrot.py— lines 125, 127 -
machine_learning/automatic_differentiation.py— lines 262, 273 -
networking_flow/minimum_cut.py— lines 85, 86
(Line numbers are as of master today; they may drift, so re-run the check below rather than trusting them blindly.)
How to work on it
uv sync --python 3.14
# temporarily flip the rule on to see only these findings:
uv run --with ty ty check --exclude-scripts --error-on-warning \
--config-file <(sed 's/rules.invalid-assignment = "ignore"/rules.invalid-assignment = "error"/' pyproject.toml)Or simply delete the rules.invalid-assignment = "ignore" line in pyproject.toml locally while you work, fix the reported spots, and confirm the count reaches zero.
When all 23 are fixed, remove the rules.invalid-assignment = "ignore" line from [tool.ty] in pyproject.toml in the same PR — that's what turns the rule on for good. Please keep runtime behaviour identical (annotations only; no logic changes) and make sure pytest --doctest-modules still passes for any file you touch.
Happy to review — feel free to take one file or the whole set. First-timers welcome. 🙂
Activity
priya-sundaram-dev commentedon Sep 6, 2026
Closing this as a duplicate of #15199, which covers the identical scope (the
invalid-assignmentslice of #15187) and already has someone working on it. Consolidating there to avoid two contributors picking up the same task. Apologies for the noise!cclauss commentedon Sep 7, 2026
I would advocate a different approach. I see nothing wrong with two different collaborators working on the same issues or algorithms because each time I have seen this happen, it has been a learning experience. We are not in a competition to land our pull requests. Instead we in a collaboration to discovery and learn what makes the best implementation and the most robust set of tests.
priya-sundaram-dev commentedon Sep 7, 2026
That's a fair point, and I'll defer to it — reopening. I closed it worried about two people redundantly editing the same 23 spots, but you're right that parallel attempts are a feature, not a bug: they surface different test strategies and edge cases, and reviewing both is where the learning happens. Thanks for the reframe. I'll leave #15204 and #15199 both open and let contributors self-select; happy to review whatever lands.