Skip to content

MAINT: Fix the ty unsound-assignment findings in memory, cli and common (UA-7) - #4517

Open
Aditya Malkar (adimalkar) wants to merge 3 commits into
microsoft:mainfrom
adimalkar:ua7-unsound-assignment
Open

Aditya Malkar (adimalkar) wants to merge 3 commits into
microsoft:mainfrom
adimalkar:ua7-unsound-assignment

Conversation

@adimalkar

Copy link
Copy Markdown
Contributor

Description

UA-7 for #4402: fixes the 12 unsound-assignment findings in pyrit/memory (without memory_models.py), pyrit/cli and pyrit/common, and removes their eight files from the temporary override in pyproject.toml, so the rule now checks them.

  • Typed at the source: _poll_until_terminal_async takes a PyRITApiClient instead of Any. Log levels come from logging.getLevelNamesMapping() instead of getattr(logging, ...). The scenario retry count is read with a typed session.scalar(select(...)).
  • Validated before assignment: the catalog pagination cursor, the ODBC query timeout and the Alembic connection are narrowed in a local before they are assigned. The HTTP error text is held as object until it is checked.
  • YamlLoadable.from_yaml_file drops its # type: ignore, and raises TypeError when a class's from_dict returns another type. A test covers the rejected case.
  • cast with a comment where the type holds by construction: aioodbc.connect (aioodbc ships no types), the SAS token value, and the translated argv stored by _parse_args_with_scenario_params.
  • _execute_get_seed_dataset_names keeps rows that are str. SeedEntry.dataset_name has no Mapped annotation, so its rows are typed Any. Annotating it would remove this check, but memory_models.py is under the permanent override, so that is left for a separate change.

Behavior changes, all on paths that were previously typed as impossible:

  • _execute_increment_scenario_number_tries raises ValueError if the row disappears between the update and the read. Before, it returned None from a function annotated -> int.
  • The Alembic env.py raises when the configured connection is not a SQLAlchemy Connection, not only when it is missing.
  • from_yaml_file raises TypeError when from_dict returns another type, as above.

This change was developed with AI assistance (Claude Code).

…on (UA-7)

Fix the 12 unsound-assignment findings in pyrit/memory (without
memory_models.py), pyrit/cli and pyrit/common, for microsoft#4402 (UA-7).

- Type at the source: PyRITApiClient for the polling client,
  logging.getLevelNamesMapping() for log levels, and the typed
  session.scalar(select(...)) for the scenario retry count.
- Validate into a local before assigning (catalog cursor, ODBC timeout,
  Alembic connection) and narrow the response text as object.
- YamlLoadable.from_yaml_file drops its type: ignore and raises TypeError
  when from_dict returns another type, with a test.
- cast with a comment where the type holds by construction: aioodbc.connect,
  the SAS token value, and the translated argv.
With their findings fixed, pyrit/memory (without memory_models.py),
pyrit/cli and pyrit/common are checked by the rule.

Relates to microsoft#4402
Copilot AI balanced review requested due to automatic review settings November 21, 2026 08:25

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

2 participants