Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ all = "error"
# Annotating those generics is real code work, so keep the rule deferred until
# that numpy-generics debt is addressed.
missing-type-argument = "ignore"
unsound-assignment = "ignore"
# unused-type-ignore-comment is environment-dependent: a `# type: ignore`
# on an optional-dependency import (torch, playwright, etc.) is "used" when the
# extra is not installed but "unused" once it is. CI installs `--extra all`, so
Expand Down Expand Up @@ -303,6 +302,76 @@ invalid-argument-type = "ignore"
invalid-method-override = "ignore"
no-matching-overload = "ignore"
unresolved-attribute = "ignore"
# Tests read fixtures through `request.getfixturevalue(...)` and other Any-typed helpers into
# annotated locals (32 findings). #4402 covers pyrit/ only, so the rule stays off for tests.
unsound-assignment = "ignore"
Comment on lines +305 to +307

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.

This is one of the two conflict spots: #4412 appended missing-type-argument = "ignore" (with its own comment) at the same place. Keep both when you merge main.

Keeping the rule off for tests/unit is the right call: make ty checks tests/unit, and #4402 only measured pyrit/.

Optional: drop the (32 findings) count. It is 33 on current main and will keep drifting.


# SQLAlchemy 2.0 declarative models are written as `col: Mapped[T] = mapped_column(...)`
# and `rel: Mapped[T] = relationship(...)`. Both calls are typed as returning Any-like
# values, so unsound-assignment flags every column and relationship (196 findings with
# one root cause). This is the documented idiom, not an unchecked boundary, and the
# migrations depend on this file, so the rule stays off here permanently.
Comment on lines +309 to +313

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.

Optional wording fix. On current main this file has 214 findings, not 196, and one of them is not the declarative idiom:

pyrit/memory/memory_models.py:2798:33: error[unsound-assignment] Unsound assignment: `Any` is not a subtype of `dict[str, str] | None`

That is display_group_map = json.loads(self.display_group_map_json). The override is file-wide, so it is exempt too. That follows from the approach #4402 chose and is not something to fix in this PR, but the comment should not say "one root cause" or carry a count that goes stale. The two calls also return MappedColumn[Any] and _RelationshipDeclared[Any], which is more precise than "Any-like".

Suggested change
# SQLAlchemy 2.0 declarative models are written as `col: Mapped[T] = mapped_column(...)`
# and `rel: Mapped[T] = relationship(...)`. Both calls are typed as returning Any-like
# values, so unsound-assignment flags every column and relationship (196 findings with
# one root cause). This is the documented idiom, not an unchecked boundary, and the
# migrations depend on this file, so the rule stays off here permanently.
# SQLAlchemy 2.0 declarative models are written as `col: Mapped[T] = mapped_column(...)`
# and `rel: Mapped[T] = relationship(...)`. Those calls return `MappedColumn[Any]` and
# `_RelationshipDeclared[Any]`, so unsound-assignment flags every column and relationship.
# This is the documented idiom, not an unchecked boundary, and the migrations depend on
# this file, so the rule stays off here permanently. The override is file-wide: other
# assignments in this file are not checked by the rule either.

[[tool.ty.overrides]]
include = ["pyrit/memory/memory_models.py"]
[tool.ty.overrides.rules]
unsound-assignment = "ignore"

# TEMPORARY: files with unsound-assignment findings still to fix, tracked in
# https://github.com/microsoft/PyRIT/issues/4402 (chunks UA-1 to UA-7). Each chunk's PR
# fixes its findings and removes its files from this list; the PR that empties the list
# deletes this override. Do not add files here: new code is checked by the rule.
[[tool.ty.overrides]]
include = [
"pyrit/auth/browser_session_copilot_authenticator.py",
"pyrit/backend/middleware/runtime.py",
"pyrit/backend/routes/targets.py",
"pyrit/backend/routes/version.py",
"pyrit/backend/services/attack_service.py",
"pyrit/backend/services/finding_export.py",

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.

Required. #4134 added pyrit/backend/services/prompt_generation_service.py to main after this branch was cut, and it has one finding:

pyrit/backend/services/prompt_generation_service.py:850:35: error[unsound-assignment] Unsound assignment: `Any | None` is not a subtype of `PromptTarget | None`

With this PR applied to current main, that is the only thing ty check pyrit and make ty report (same on Python 3.11 and 3.14), so it needs to be in the list. UA-4 will take it out again.

Suggested change
"pyrit/backend/services/finding_export.py",
"pyrit/backend/services/finding_export.py",
"pyrit/backend/services/prompt_generation_service.py",

"pyrit/backend/services/scenario_service.py",
"pyrit/cli/api_client.py",
"pyrit/cli/pyrit_scan.py",
"pyrit/common/cli_helpers.py",
"pyrit/common/yaml_loadable.py",
"pyrit/converter/decomposition_converter.py",
"pyrit/embedding/openai_text_embedding.py",
"pyrit/executor/attack/multi_turn/tree_of_attacks.py",
"pyrit/executor/attack/single_turn/many_shot_jailbreak.py",
"pyrit/executor/promptgen/gcg/attack/base/attack_manager.py",
"pyrit/executor/promptgen/gcg/attack/gcg/candidate_proposer.py",
"pyrit/executor/promptgen/gcg/attack/gcg/gcg_attack.py",
"pyrit/executor/promptgen/gcg/default_implementations.py",
"pyrit/memory/alembic/env.py",
"pyrit/memory/attack_analytics.py",
"pyrit/memory/azure_sql_memory.py",
"pyrit/memory/memory_interface.py",
"pyrit/models/harm_category.py",
"pyrit/models/messages/conversations.py",
"pyrit/models/parameter.py",
"pyrit/models/score/observation.py",
"pyrit/models/score/scorable.py",
"pyrit/prompt_normalizer/json_retry.py",
"pyrit/prompt_normalizer/prompt_normalizer.py",
"pyrit/prompt_target/azure_blob_storage_target.py",
"pyrit/prompt_target/common/discover_target_capabilities.py",
"pyrit/prompt_target/openai/openai_error_handling.py",
"pyrit/prompt_target/openai/openai_response_target.py",
"pyrit/prompt_target/prompt_shield_target.py",
"pyrit/registry/components/target_registry.py",
"pyrit/registry/registry_recipe_restore.py",
"pyrit/registry/registry_recipe_rules.py",
"pyrit/registry/registry_recipe_save.py",
"pyrit/scenario/core/attack_technique_factory.py",
"pyrit/scenario/scenarios/foundry/assert_policy.py",
"pyrit/score/float_scale/local_violence_classifier_scorer.py",
"pyrit/score/llm_scoring.py",
"pyrit/score/observation/otel_execution_trace_source.py",
"pyrit/score/scorer.py",
"pyrit/score/scorer_prompt_validator.py",
"pyrit/score/true_false/prompt_shield_scorer.py",
]
[tool.ty.overrides.rules]
unsound-assignment = "ignore"

[tool.uv]
constraint-dependencies = [
Expand Down