Skip to content

typing: preserve ToolExecutionMetadata subclasses - #3992

Merged
Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
huong8373tt-beep:feat/py311-tool-execution-metadata
Nov 6, 2026
Merged

Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
huong8373tt-beep:feat/py311-tool-execution-metadata

Conversation

@huong8373tt-beep

Copy link
Copy Markdown
Contributor

Summary

  • Annotate ToolExecutionMetadata.from_metadata with Self | None so the return type matches its existing cls.model_validate(...) construction.
  • Add focused subclass runtime and assert_type coverage.
  • Preserve absent-metadata behavior, strict invoked validation, frozen/extra-forbid behavior, metadata round trips, and input immutability.

Part of #3166 (P311-01).

Validation

  • uv run --group dev pytest tests/unit/models/test_tool_execution_metadata.py -q — 11 passed
  • uv run --group dev ruff check pyrit/models/target/tool_execution_metadata.py tests/unit/models/test_tool_execution_metadata.py
  • uv run --group dev ruff format --check pyrit/models/target/tool_execution_metadata.py tests/unit/models/test_tool_execution_metadata.py
  • uv run --group dev ty check tests/unit/models/test_tool_execution_metadata.py pyrit/models/target/tool_execution_metadata.py
  • git diff --check

AI disclosure

Slai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 23:56

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.

🟢 Approval recommended

No active review issues were identified for the subclass-aware return-typing update.

No open issues 🎉

What changed in this PR

This PR improves subclass-aware typing for ToolExecutionMetadata.from_metadata as part of #3166’s Python 3.11 Self adoption, without changing runtime behavior.

Changes:

  • Changes the factory return annotation and docstring to Self | None.
  • Adds runtime and static type assertions for subclass reconstruction, plus an input-immutability test.
File Description
tests/​unit/​models/​test_tool_execution_metadata.py Adds subclass typing, runtime identity, and input-immutability checks.
pyrit/​models/​target/​tool_execution_metadata.py Uses `Self

Review effort: Balanced

@romanlutz
Roman Lutz (romanlutz) merged commit 4b0383c into microsoft:main Nov 6, 2026
57 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.

3 participants