Repository navigation
typing: preserve ToolExecutionMetadata subclasses - #3992
Merged
Roman Lutz (romanlutz) merged 2 commits intoNov 6, 2026
Merged
Roman Lutz (romanlutz) merged 2 commits into
Roman Lutz (romanlutz) merged 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟢 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
19 of 25 tasks
Roman Lutz (romanlutz)
self-requested a review
November 6, 2026 00:40
Roman Lutz (romanlutz)
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ToolExecutionMetadata.from_metadatawithSelf | Noneso the return type matches its existingcls.model_validate(...)construction.assert_typecoverage.invokedvalidation, 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 passeduv run --group dev ruff check pyrit/models/target/tool_execution_metadata.py tests/unit/models/test_tool_execution_metadata.pyuv run --group dev ruff format --check pyrit/models/target/tool_execution_metadata.py tests/unit/models/test_tool_execution_metadata.pyuv run --group dev ty check tests/unit/models/test_tool_execution_metadata.py pyrit/models/target/tool_execution_metadata.pygit diff --checkAI disclosure
Slai Agent Runtime performed the investigation, implementation, and test execution. The account owner authorized this contribution and is responsible for its content.