Skip to content

MAINT: Enable the ty unsound-assignment rule with staged overrides (UA-0) - #4407

Merged
Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
mss06s:maint/ty-unsound-assignment-ua0
Nov 21, 2026
Merged

Roman Lutz (romanlutz) merged 4 commits into
microsoft:mainfrom
mss06s:maint/ty-unsound-assignment-ua0

Conversation

@mss06s

Copy link
Copy Markdown
Contributor

Description

UA-0 for #4402: turns on ty's unsound-assignment rule so new code is checked from day one, with the remaining findings fenced off for UA-1 to UA-7. Configuration only, no source changes.

  • Removed unsound-assignment = "ignore" from [tool.ty.rules].
  • Added a permanent [[tool.ty.overrides]] for pyrit/memory/memory_models.py (the SQLAlchemy Mapped[T] = mapped_column(...) / relationship(...) idiom, 196 findings), with a comment explaining why.
  • Added a temporary [[tool.ty.overrides]] for the files that still have findings, with a comment pointing to MAINT: Enable the ty unsound-assignment rule in stages (267 findings) #4402.

One difference from the issue: main has moved since fdeb9c5, and the GCG refactor added findings in three files that weren't on the list: gcg/attack/gcg/candidate_proposer.py (4), gcg/attack/gcg/gcg_attack.py (1) and gcg/default_implementations.py (6), and attack_manager.py now has 17. I added the three files to the temporary override next to attack_manager.py, so UA-1 now covers 28 findings in 4 files (283 in total, not 267). It may be worth updating the issue's table.

ty check pyrit passes, and a file outside the list is flagged by the rule.

…A-0)

Remove `unsound-assignment = "ignore"` from [tool.ty.rules] so the rule
runs at `all = "error"` like the others, and add two overrides:

- a permanent one for pyrit/memory/memory_models.py, where every finding
  is the SQLAlchemy 2.0 `Mapped[T] = mapped_column(...)` /
  `relationship(...)` idiom (196 findings, one root cause);
- a temporary one for the 47 files that still have findings, to be
  emptied by chunks UA-1 to UA-7.

Since the issue was measured, the GCG refactor added findings in
candidate_proposer.py, gcg_attack.py and default_implementations.py; they
are in the temporary list with attack_manager.py, so UA-1 now covers 28
findings in 4 files. `ty check pyrit` passes, and every file not listed
is checked by the rule.

Part of microsoft#4402 (UA-0).
Copilot AI balanced review requested due to automatic review settings November 18, 2026 22:35
@mss06s

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Removing the global ignore enables unsound-assignment in unit tests, where existing Any-to-concrete assignments cause the full CI typing check to fail.

1 open issue
What changed in this PR

Implements UA-0 of #4402 by enabling ty’s unsound-assignment rule while deferring existing findings through scoped overrides. This is a configuration-only change.

Changes:

  • Removes the global rule suppression.
  • Adds a permanent exemption for SQLAlchemy declarations in memory_models.py.
  • Adds a temporary exemption for 47 files pending UA-1 through UA-7, including three newly affected GCG files.
File Description
pyproject.toml Enables the rule globally and adds permanent and staged file-level exemptions.

Review effort: Balanced

Comment thread pyproject.toml Resolved
make ty also checks tests/unit, where fixtures read through
request.getfixturevalue(...) and other Any-typed helpers into annotated
locals give 32 unsound-assignment findings. microsoft#4402 covers pyrit/ only, so
add the rule to the existing tests/unit override. make ty passes.
@Steeve-Crypto

Copy link
Copy Markdown
Contributor

Heads up: pyrit/backend/services/prompt_generation_service.py (added in #4134) has an unsound-assignment finding that isn't in the temporary override list here, so make ty will likely fail on this branch after a rebase. You could add it to the override for now. My UA-4 PR for pyrit/backend fixes it at the source, so it can come out again once that lands.

Comment thread pyproject.toml Resolved
Comment thread pyproject.toml Resolved
Comment thread pyproject.toml Resolved
Resolve the pyproject.toml conflict with microsoft#4412 by keeping both sides: the
global unsound-assignment ignore stays deleted, and the tests/unit override
keeps microsoft#4412's missing-type-argument line followed by this PR's block.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
pyrit/backend/services/prompt_generation_service.py (added in microsoft#4134) has one
unsound-assignment finding, so it joins the temporary override until UA-4
fixes it. Without it ty check pyrit fails on current main.

Also drop the finding counts from the tests and memory_models comments, since
they drift with every merge, name the types the SQLAlchemy calls return, and
note that the permanent override is file-wide.

Part of microsoft#4402 (UA-0).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@romanlutz Roman Lutz (romanlutz) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both blockers from my review are fixed. I pushed two commits to this branch:

  • bcc030f merges main and resolves the pyproject.toml conflict with #4412, keeping both sides.
  • 185b6e6 adds pyrit/backend/services/prompt_generation_service.py to the temporary list, drops the finding counts from the two comments, and notes that the memory_models.py override is file-wide.

On the merged tree the temporary list is again exactly the set of pyrit/ files with findings (48), and make ty passes locally. Thanks for taking UA-0, Mohammad Saeed (@mss06s).

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 21, 2026
Merged via the queue into microsoft:main with commit a943e99 Nov 21, 2026
65 checks passed
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.

4 participants