Repository navigation
MAINT: Enable the ty unsound-assignment rule with staged overrides (UA-0) - #4407
Roman Lutz (romanlutz) merged 4 commits into
Conversation
…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).
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
🟡 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
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.
|
Heads up: |
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>
Roman Lutz (romanlutz)
left a comment
There was a problem hiding this comment.
Both blockers from my review are fixed. I pushed two commits to this branch:
bcc030fmergesmainand resolves thepyproject.tomlconflict with #4412, keeping both sides.185b6e6addspyrit/backend/services/prompt_generation_service.pyto the temporary list, drops the finding counts from the two comments, and notes that thememory_models.pyoverride 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).

Description
UA-0 for #4402: turns on ty's
unsound-assignmentrule 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.unsound-assignment = "ignore"from[tool.ty.rules].[[tool.ty.overrides]]forpyrit/memory/memory_models.py(the SQLAlchemyMapped[T] = mapped_column(...)/relationship(...)idiom, 196 findings), with a comment explaining why.[[tool.ty.overrides]]for the files that still have findings, with a comment pointing to MAINT: Enable the tyunsound-assignmentrule in stages (267 findings) #4402.One difference from the issue:
mainhas moved sincefdeb9c5, 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) andgcg/default_implementations.py(6), andattack_manager.pynow has 17. I added the three files to the temporary override next toattack_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 pyritpasses, and a file outside the list is flagged by the rule.