Skip to content

typing: preserve GCG config subclasses - #4064

Merged
Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
huong8373tt-beep:feat/py311-gcg-config-self
Nov 9, 2026
Merged

Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
huong8373tt-beep:feat/py311-gcg-config-self

Conversation

@huong8373tt-beep

Copy link
Copy Markdown
Contributor

Summary

  • use typing.Self for the GCG JSON and JSON-file classmethod factories
  • preserve concrete subclasses through GCGDataConfig and GCGConfig deserialization
  • add runtime and assert_type regression coverage

Scope

Part of #3166 (P311-01). This focused change preserves the existing JSON parsing, validation, defaults, nested config construction, and file behavior.

Validation

  • pytest tests/unit/executor/promptgen/gcg/test_config.py -q (32 passed)
  • ruff check (passed)
  • ruff format --check (passed)
  • ty check (passed)

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

Copilot AI balanced review requested due to automatic review settings November 8, 2026 16:57

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 are identified for the concrete-type preservation changes.

No open issues 🎉

What changed in this PR

This PR strengthens concrete-type preservation in PyRIT’s GCG configuration factories and scenario technique resolution, extending the typing work tracked in #3166.

Changes:

  • Annotates GCG JSON factories with Self, preserving existing construction and validation behavior.
  • Makes technique-token resolution generic over the supplied technique class.
  • Adds runtime and assert_type regression coverage for both paths.
File Description
tests/​unit/​scenario/​core/​test_technique_tokens.py Tests concrete technique types, modifier ordering, and invalid-token reporting.
tests/​unit/​executor/​promptgen/​gcg/​test_config.py Adds subclass runtime and type assertions for JSON and file factories.
pyrit/​scenario/​core/​technique_tokens.py Adds generic technique typing and a typed converter registry reference.
pyrit/​executor/​promptgen/​gcg/​config.py Uses Self for JSON factories and the internal dictionary constructor.

Review effort: Balanced

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Nov 9, 2026
Merged via the queue into microsoft:main with commit 16e5461 Nov 9, 2026
59 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