Skip to content

ty: un-ignore invalid-assignment (9 files, 23 spots) — good first issue #15204

Description

@priya-sundaram-dev

Sub-task of #15187good 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" = None

Current 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions