Skip to content

[BREAKING] MAINT: Migrate the remaining str enums to StrEnum and enable UP042 (#4508) - #4644

Open
Aditya Malkar (adimalkar) wants to merge 1 commit into
microsoft:mainfrom
adimalkar:maint/4508-strenum-batch
Open

Aditya Malkar (adimalkar) wants to merge 1 commit into
microsoft:mainfrom
adimalkar:maint/4508-strenum-batch

Conversation

@adimalkar

Copy link
Copy Markdown
Contributor

Description

Moves the remaining str, Enum classes to StrEnum and re-enables Ruff's UP042, which is PR 3 of #4508.

  • 67 classes in pyrit/ and one frontend e2e fixture are migrated. Members, values, equality, JSON and the backend's OpenAPI schema are unchanged.
  • UP042 is no longer ignored, so new str, Enum classes fail pre-commit. AttackOutcome keeps a noqa until [BREAKING] MAINT: Migrate AttackOutcome to StrEnum #4589 migrates it.
  • One parametrized test checks that each class is a StrEnum, formats as its value and round-trips.
  • Two exhaustiveness tests paste an enum's source into a probe file, so the probe now imports StrEnum.

The tracker's sweep counted 61 classes and main now has 67, so the batch was rechecked by recording every str()/format() of these members during a full tests/unit run on main. The only site hit is _coerce_enum in pyrit/models/parameter.py, which returns the same member before and after.

Release note. str(member), f"{member}" and "%s" % member now give the value (skip) instead of IncompatibleTechniquePolicy.SKIP. Code that depends on the old text should use type(member).__name__ and member.name. repr(member) is unchanged. Public exports affected:

51 classes
  • pyrit.analytics: PairedOutcomeTransition
  • pyrit.converter: PuzzleType
  • pyrit.executor.attack: SequenceCompletionPolicy
  • pyrit.models: Acquisition, AssertPatternRole, AssertReplication, AssertSampleVote, AssertSamplingMethod, AssertSkipReason, AttackAnalyticsConverterDirection, AttackAnalyticsDimensionName, AttackAnalyticsMatchMode, AttackAnalyticsValueKind, AttackResultRole, AttackResultSelection, CapabilityName, DatasetFetchPolicy, DatasetLimitState, DatasetSelectionMode, ExecutionStepKind, Modality, ParameterDestination, PromptGenerationStatus, ScenarioDatasetSizeEstimateKind, ScenarioObjectiveScorerAttribution, ScenarioObjectiveScorerScope, ScenarioRunPlanGroupKind, ScenarioRunSizeEstimateCondition, ScenarioRunSizeEstimateStatus, ScenarioSuiteExecutionStatus, ScenarioSuiteSubmissionState, ScoreStatus, ScorerCapabilityName, ScorerVerdictStatus, SurfaceMatch, ToolCaptureGap, ToolLoopStopReason, TraceSpanStatus, WebSearchMode
  • pyrit.models.catalog: RegistryEntryOrigin, RegistryRecipeKind, RestoreFailureReason
  • pyrit.prompt_target: UnsupportedCapabilityBehavior
  • pyrit.scenario: IncompatibleTechniquePolicy
  • pyrit.scenario.core: ScorerOverridePolicy
  • pyrit.score: AssertJudgmentMode, AssertScoringDimension, RobloxPiiCategory, ScorerMismatchKind, TraceEvidenceRequirement
  • pyrit.setup.initializers.techniques: TechniqueInitializerTags

Relates to #4508

AI assistance: Claude Code wrote this change and ran the checks.

…le UP042

PR 3 of microsoft#4508: 67 classes in pyrit/ and one e2e fixture. str(member) and
f-strings now give the value instead of Class.MEMBER; values, equality and
JSON are unchanged. AttackOutcome keeps a noqa until microsoft#4589 migrates it.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 19:58

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

2 participants