Repository navigation
MAINT: preserve subclass type for request trace metadata - #3897
Roman Lutz (romanlutz) merged 1 commit into
Conversation
Update RequestTraceContext.from_metadata to return Self when metadata is present and add subclass type regression coverage. Signed-off-by: Slai.life <huong8373tt@gmail.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the subclass-preserving return-type update.
No open issues 🎉
What changed in this PR
This PR extends Python 3.11 Self adoption under #3166 by making RequestTraceContext.from_metadata reflect its existing subclass-preserving behavior. Runtime construction remains unchanged.
Changes:
- Update the return annotation and docstring to
Self | None. - Add regression tests for subclass typing and reconstruction, absent metadata, and input non-mutation.
| File | Description |
|---|---|
tests/unit/models/test_request_trace_context.py |
Adds focused type and runtime regression coverage. |
pyrit/models/target/request_trace_context.py |
Uses `Self |
Review effort: Balanced
|
I reviewed the current checks. The remaining failures are unrelated baseline/infrastructure issues: the documentation build cannot resolve the existing |
|
The current PR code and focused checks are complete. The remaining failed checks are unrelated baseline issues: the strict docs build cannot resolve the existing cla.opensource.microsoft.com link, and macOS 3.12 dev_all has an unrelated chat-scoring timeout (34351 passed, 1 unrelated failure). No changes are needed for this PR. |
Summary
RequestTraceContext.from_metadatato returnSelf | None, matching its existingcls(...)construction behavior.Part of #3166.
Validation
uv run --group dev pytest tests/unit/models/test_request_trace_context.py -quv run --group dev pytest tests/unit/score/test_message_trace_scoring.py -quv run --group dev ruff check pyrit/models/target/request_trace_context.py tests/unit/models/test_request_trace_context.pyuv run --group dev ruff format --check pyrit/models/target/request_trace_context.py tests/unit/models/test_request_trace_context.pyuv run --group dev ty check pyrit/models/target/request_trace_context.py tests/unit/models/test_request_trace_context.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.