Skip to content

MAINT: preserve subclass type for request trace metadata - #3897

Merged
Roman Lutz (romanlutz) merged 1 commit into
microsoft:mainfrom
huong8373tt-beep:fix/request-trace-context-self-3166
Nov 4, 2026
Merged

Roman Lutz (romanlutz) merged 1 commit into
microsoft:mainfrom
huong8373tt-beep:fix/request-trace-context-self-3166

Conversation

@huong8373tt-beep

Copy link
Copy Markdown
Contributor

Summary

  • Update RequestTraceContext.from_metadata to return Self | None, matching its existing cls(...) construction behavior.
  • Add focused regression coverage for subclass reconstruction, absent metadata, and input non-mutation.

Part of #3166.

Validation

  • uv run --group dev pytest tests/unit/models/test_request_trace_context.py -q
  • uv run --group dev pytest tests/unit/score/test_message_trace_scoring.py -q
  • uv run --group dev ruff check pyrit/models/target/request_trace_context.py tests/unit/models/test_request_trace_context.py
  • uv run --group dev ruff format --check pyrit/models/target/request_trace_context.py tests/unit/models/test_request_trace_context.py
  • uv run --group dev ty check pyrit/models/target/request_trace_context.py tests/unit/models/test_request_trace_context.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.

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>

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-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

@huong8373tt-beep

Copy link
Copy Markdown
Contributor Author

I reviewed the current checks. The remaining failures are unrelated baseline/infrastructure issues: the documentation build cannot resolve the existing https://cla.opensource.microsoft.com link, and macOS 3.12 dev_all is the existing chat-scoring timeout. The type/runtime changes in this PR have no active review issues, so I am not expanding the PR scope to unrelated failures.

@huong8373tt-beep

Copy link
Copy Markdown
Contributor Author

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.

@romanlutz Roman Lutz (romanlutz) changed the title models: preserve subclass type for request trace metadata MAINT: preserve subclass type for request trace metadata Nov 4, 2026
@romanlutz
Roman Lutz (romanlutz) merged commit 9960a8d into microsoft:main Nov 4, 2026
62 of 65 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