Skip to content

MAINT: Enable ty missing-type-argument rule - #4412

Merged
Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
romanlutz:claude/ty-missing-type-argument-26c5c6
Nov 20, 2026
Merged

Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
romanlutz:claude/ty-missing-type-argument-26c5c6

Conversation

@romanlutz

@romanlutz Roman Lutz (romanlutz) commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Turn on ty's missing-type-argument rule for pyrit/ by removing its "ignore" override in pyproject.toml and parameterising the 14 bare generics it flags. The rule stays relaxed for tests/unit/** through the existing unit-test override (318 bare generics there), so make ty remains clean.

  • dict (5): cli/_config_reader.py, datasets/.../multilingual_vulnerability_dataset.py, models/harm_category.py, models/score/score.py, score/float_scale/float_scale_score_aggregator.py. Each takes the type its callers already use (dict[str, str] for a dataset row, dict[str, str | int | float] for score metadata, dict[str, Any] for parsed YAML).
  • os.PathLike (2): common/safe_extract.py now says os.PathLike[str], which is what zipfile.ZipFile and Path accept.
  • SQLAlchemy Select (4): the statement builders in memory/memory_interface.py. The message-page builder is Select[PromptMemoryEntry]. The three scenario-delta builders are Select[*tuple[Any, ...]]: the projection has 25 columns, SQLAlchemy only types the first 10, and callers read rows through .mappings().
  • AttackStrategy (3): registry/components/attack_registry.py uses AttackStrategy[Any, Any], the spelling already used for heterogeneous strategies in attack_technique_factory.py.

Notes for reviewers:

  • Why the rule can be enabled now. It was deferred because bare np.ndarray is flagged under numpy 2.2.x. uv.lock now pins numpy 2.4.6 for every supported Python, 3.11 included, and there ndarray's type parameters have defaults. ty 0.0.99 reports the same 14 findings on Python 3.11 and 3.14 before this change and none after. The np.ndarray annotations are untouched; they would be flagged again (42 sites) only if the lock moved back below numpy 2.4.
  • One change is a runtime value, not an annotation. In models/score/score.py the flagged dict is the argument PlainSerializer(..., return_type=dict | None), now dict[str, Any] | None to match ComponentIdentifier's serializer. Pydantic's internal key serializer for that field goes from any to str; the JSON schemas of Score, MessagePiece and Conversation and a sample Score dump are byte-identical before and after.

🤖 Generated with Claude Code

Remove the `missing-type-argument = "ignore"` override so the rule runs
under `[tool.ty.rules] all = "error"`, and parameterise the 14 bare
generics it flags in pyrit/:

- dict: cli/_config_reader, datasets multilingual_vulnerability_dataset,
  models/harm_category, models/score/score, score float_scale aggregator
- os.PathLike: common/safe_extract (ZipSource and dest_dir)
- sqlalchemy Select: four statement builders in memory/memory_interface
- AttackStrategy: registry/components/attack_registry

The rule was deferred because bare `np.ndarray` generics are flagged under
numpy 2.2.x. uv.lock now pins numpy 2.4.6 for every supported Python
(3.11 included), where ndarray's type parameters have defaults, so those
annotations are no longer findings. ty 0.0.99 reports the same 14
findings on Python 3.11 and 3.14 before this change and none after.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 19, 2026 00:24

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 override exposes bare-generic annotations in unit tests to missing-type-argument errors, causing the CI make ty check to fail.

1 open issue
What changed in this PR

This PR enables ty’s missing-type-argument rule and parameterizes 14 bare generics in PyRIT’s production code.

Changes:

  • Removes the global suppression for missing-type-argument.
  • Adds explicit type arguments for dictionaries, paths, SQLAlchemy statements, and attack strategies.
  • Updates the score identifier serializer’s declared return type.
File Description
pyrit/​score/​float_scale/​float_scale_score_aggregator.py Types aggregator metadata and updates its docstring.
pyrit/​registry/​components/​attack_registry.py Parameterizes heterogeneous attack strategy types.
pyrit/​models/​score/​score.py Specifies the serializer’s dictionary return type.
pyrit/​models/​harm_category.py Types the parsed YAML mapping.
pyrit/​memory/​memory_interface.py Adds type arguments to four query builders.
pyrit/​datasets/​seed_datasets/​remote/​multilingual_vulnerability_dataset.py Types dataset rows as string dictionaries.
pyrit/​common/​safe_extract.py Specifies string-based path-like inputs.
pyrit/​cli/​_config_reader.py Types configuration mappings and updates the docstring.
pyproject.toml Removes the missing-type-argument suppression.

Review effort: Balanced

Comment thread pyproject.toml Resolved
CI's `make ty` checks tests/unit as well as pyrit/. Enabling the rule
repo-wide surfaced 318 bare generics in tests/unit, failing that step.
Add the rule to the existing tests/unit override so it is enforced for
pyrit/ only, matching how other strict rules are relaxed for tests.

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

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.

Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 20, 2026
Merged via the queue into microsoft:main with commit 7557382 Nov 20, 2026
65 checks passed
@romanlutz
Roman Lutz (romanlutz) deleted the claude/ty-missing-type-argument-26c5c6 branch November 20, 2026 07:05
Roman Lutz (romanlutz) added a commit to mss06s/PyRIT that referenced this pull request Nov 21, 2026
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>
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.

3 participants