Skip to content

MAINT Migrate ConversationRetryReason to StrEnum (P311-17) - #3850

Merged
Roman Lutz (romanlutz) merged 1 commit into
microsoft:mainfrom
juliosuas:maint/p311-17-strenum
Nov 3, 2026
Merged

Roman Lutz (romanlutz) merged 1 commit into
microsoft:mainfrom
juliosuas:maint/p311-17-strenum

Conversation

@juliosuas

Copy link
Copy Markdown
Contributor

Part of #3166 (P311-17: assess enum.StrEnum). PyRIT requires Python >= 3.11, so enum.StrEnum is available.

This migrates one enum, ConversationRetryReason, from (str, Enum) to StrEnum. It was chosen because no code path relies on str()/format() producing the class-qualified form. Persistence goes through ConversationRetry.model_dump(mode="json"), which already stores the value, and comparisons use members or plain-string equality, which behave the same under both bases.

The only observable change is that str(member) and format(member) now return "json_parsing" instead of "ConversationRetryReason.JSON_PARSING".

Tests: added tests/unit/models/test_conversation_retry.py, which pins str(), f-string and format() output, string equality, value lookup, json.dumps, and the pydantic JSON round trip. Existing retry, memory and crescendo-resume tests pass; ty, pre-commit and the unit suite pass locally.

The other (str, Enum) classes in pyrit/ could follow the same way, one by one, after checking each for uses of the qualified str() form.

This PR was prepared with AI assistance and reviewed by me.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 06:42

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 remain for the focused migration of ConversationRetryReason to StrEnum.

No open issues 🎉

What changed in this PR

Migrates ConversationRetryReason to Python 3.11’s StrEnum as a focused step toward #3166 (P311-17), preserving retry values and JSON serialization.

Changes:

  • Replaces the (str, Enum) base with StrEnum.
  • Adds tests for string rendering, equality, value lookup, JSON encoding, and Pydantic serialization round trips.
File Description
tests/​unit/​models/​test_conversation_retry.py Adds regression coverage for enum behavior and serialization.
pyrit/​models/​messages/​conversation_retry.py Changes ConversationRetryReason to inherit from StrEnum.

Review effort: Balanced

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